Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 7, 2026. It is now read-only.
This repository was archived by the owner on May 7, 2026. It is now read-only.

Instantiating a client with credentials from a service account credentials file does not use the right project name. #74

Copy link
Copy link

Description

@tomthorogood
Issue body actions

Steps to reproduce

  1. Using the vended service_account.Credentials.from_service_account_file, create a Credentials object that defines a different project than the configured environment. (As in "Someone from Project X gave me credentials so that I could access their datastore from my Project Y).
  2. Instantiate a client with datastore.Client(credentials=credentials), where credentials is the output from Step chore: add split repo templates #1
  3. assert client.project == credentials.project_id # AssertionError

However, this is only a part of the problem. I am able to construct and run read-only queries against datastore just fine with this mismatch. The issue strikes when I need to manipulate records, because the Batch object is performing a check to make sure that Batch.project == entity.key.project.

When I manipulate records that I fetched using a mis-configured client, the entities are correct, but the later-initialized Batch is then incorrect (and throws the error, Key must be from same project as batch) because the client is creating a Batch from its own configuration, and Batch performs a check that self.project == entity.key.project.

Code example

# From a GKE workload running on Project X, trying to manipulate a datastore on project Y
credentials = service_account.Credentials.from_service_account_file('/path/to/project-y-credentials.json')
client = datastore.Client(credentials=credentials)
print(client.project) # "project-x"
print(credentials.project_id) # "project-y"

This can easily be worked around by explicitly providing the project:

client = datastore.Cilent(credentials=credentials, project=credentials.project_id)

but is a step that nobody should have to take, and finding out that was the problem was time-consuming.


It would be great if, when provided a credentials object that defines a project, the datastore client could use credentials.project_id when determining the project name, so that distributed credentials properly configure their clients.

Thank you!

Reactions are currently unavailable

Metadata

Metadata

Labels

api: datastoreIssues related to the googleapis/python-datastore API.Issues related to the googleapis/python-datastore API.type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.