Thanks to visit codestin.com
Credit goes to github.com

Skip to content

connect() surface issues #460

@IlyaFaer

Description

@IlyaFaer

Looking at connect() function, there are several things which are raising questions.

project arg:
project is set as an optional arg:

def connect(project=None, instance=None, database=None, credentials_uri=None, user_agent=None):
But few lines lower it is checked for existence (thus, it's required, not optional):
if not project:
raise Error("'project' is required.")
It seems to be pointless, as this arg is only passed to Spanner client, and the original Spanner client can handle an omitted project: it'll use google.auth.default() function to designate the project id from the environment. With this, I'd propose to drop this check and use project arg in the way of the original Spanner client.

instance and database args:
They are optional by definition, but in fact both are required. Probably, they should become required in definition (the function signature will be connect(instance, database, project=None, credentials_uri=None, user_agent=None):), so these checks could be dropped:

if not instance:
raise Error("'instance' is required.")
if not database:
raise Error("'database' is required.")

credentials_uri arg:
This arg looks divergent from how the original Spanner client is dealing with credentials:
https://github.com/googleapis/python-spanner/blob/b6b0348f5870f55c88b3cae44e229325fd755b26/google/cloud/spanner_v1/client.py#L123-L129

I'd propose to change this arg to use google.auth.credentials.Credentials class as it's done in the original Spanner client.

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/python-spanner-django API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions