You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 13, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 13, 2026. It is now read-only.
Infer project from credentials if not passed explicitly #27
In a "blank slate" design, I would argue that the credentials' project should supersede the one present in the environment. However, for backward compatibility, we need to use the credentials' project only if the environment variable is not set. So the order should follow the pattern from google.auth.default when inferring project ID:
So, the case we need to cover for this feature is when the user has passed in explicit service account credentials, but not an explicit project ID, e.g. (this won't currently work):
$ unset GOOGLE_CLOUD_PROJECT GCLOUD_PROJECT GOOGLE_APPLICATION_CREDENTIALS
$ python
>>> from google.oauth2.service_account import Credentials
>>> credentials = Credentials.from_service_account_file("/path/to/service_account.json")
>>> from google.cloud.client import ClientWithProject
>>> client = ClientWithProject(credentials=credentials) # currently raises
Activity
tseaver commentedon Dec 8, 2020
In the case where credentials are discovered for us,
google.auth.default()already falls back to the project in the credentials. E.g.:So, the case we need to cover for this feature is when the user has passed in explicit service account credentials, but not an explicit project ID, e.g. (this won't currently work):
feat: infer project from explicit service account creds
feat: infer project from explicit service account creds (#51)
dhermes commentedon Oct 7, 2024
Is there a reasonCLOUDSDK_CORE_PROJECTisn't also supported?I made it here via the comment near a stack-trace I followed:python-cloud-core/google/cloud/client/__init__.py
Lines 252 to 260 in e5fb3ea
Update: I just did some testing and confirmed it is supported. Not sure what sort of heisenbug I was observing!