Open
Description
Describe the bug
There are 2 methods for authenticating with Spanner:
- gcp service account credentials file, and
- web-based interactive authentication
a new optional parameter was added to register() to allow passing in spanner config:
spanner_config dict must contain the include the following keys, credentials_file is optional:
- "project_id": The GCP project ID.
- "instance_id": The Spanner instance ID.
- "database_id": The Spanner database ID.
- "credentials_file": json file API key for service accounts
if using method #2 (web-based interactive auth) which does not require credentials_file, spanner_init errors with:
SpannerConnectionError: Failed to connect to Spanner: 'SpannerGraph' object has no attribute 'credentials_file'
To Reproduce
use option 2, which does not require credentials_file
to be set, then attempt to call
import pandas as pd
import graphistry
PROJECT_ID = "my_project"
INSTANCE_ID = "my_instance"
DATABASE_ID = "finance-graph-db"
# google settings, option 1: interactive login using gcloud auth application-default login (below)
SPANNER_CONF = { "project_id": PROJECT_ID,
"instance_id": INSTANCE_ID,
"database_id": DATABASE_ID }
graphistry.register(api=3, personal_key_id='xxx', personal_key_secret='xxx', server='hub.graphistry.com', spanner_config=SPANNER_CONF)
# google auth stuff:
# Set the google project id
!gcloud config set project {PROJECT_ID}
%env GOOGLE_CLOUD_PROJECT={PROJECT_ID}
# web-based interactive login to GCP:
!gcloud auth application-default login
# spanner graph query:
query=f'''GRAPH FinGraph
MATCH p = (a)-[b]->(c) where 1=1 {LIMIT_CLAUSE} return SAFE_TO_JSON(p) as path'''
g = graphistry.spanner_gql_to_g(query)
Expected behavior
should not error out as credentials_file
is not required with web-based auth
Actual behavior
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.11/dist-packages/graphistry/plugins/spannergraph.py in __connect(self)
84 try:
---> 85 if self.credentials_file:
86 connection = connect(self.instance_id, self.database_id, credentials=self.credentials_file)
AttributeError: 'SpannerGraph' object has no attribute 'credentials_file'
During handling of the above exception, another exception occurred:
SpannerConnectionError Traceback (most recent call last)
5 frames
/usr/local/lib/python3.11/dist-packages/graphistry/plugins/spannergraph.py in __connect(self)
92 return connection
93 except Exception as e:
---> 94 raise SpannerConnectionError(f"Failed to connect to Spanner: {e}")
95
96 def close_connection(self) -> None:
SpannerConnectionError: Failed to connect to Spanner: 'SpannerGraph' object has no attribute 'credentials_file'