-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Core: GOOGLE_CLOUD_PROJECT env var is not supported unless credentials are also provided in the environment #8108
Copy link
Copy link
Closed
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.authtype: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.
Description
Environment details
- Python 3.6.6, Anaconda
- Name: google-cloud-bigquery, Version: 1.11.3
Steps to reproduce
- Set GOOGLE_CLOUD_PROJECT env var to the desired project.
- run
bigquery.client(credentials=FooCredentials())
Code example
client = bigquery.Client(credentials=KaggleKernelCredentials())Stack trace
Traceback (most recent call last):
File "/input/tests/test_bigquery.py", line 112, in test_project_with_env_var_project_default_credentials
client = bigquery.Client()
File "/tmp/patches/lib/python3.6/site-packages/sitecustomize.py", line 42, in <lambda>
bq_client, *args, **kwargs)
File "/tmp/patches/lib/python3.6/site-packages/sitecustomize.py", line 35, in monkeypatch_bq
return bq_client(*args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/google/cloud/bigquery/client.py", line 150, in __init__
project=project, credentials=credentials, _http=_http
File "/opt/conda/lib/python3.6/site-packages/google/cloud/client.py", line 223, in __init__
_ClientProjectMixin.__init__(self, project=project)
File "/opt/conda/lib/python3.6/site-packages/google/cloud/client.py", line 175, in __init__
project = self._determine_default(project)
File "/opt/conda/lib/python3.6/site-packages/google/cloud/client.py", line 190, in _determine_default
return _determine_default_project(project)
File "/opt/conda/lib/python3.6/site-packages/google/cloud/_helpers.py", line 186, in _determine_default_project
_, project = google.auth.default()
File "/opt/conda/lib/python3.6/site-packages/google/auth/_default.py", line 317, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https:/
/cloud.google.com/docs/authentication/getting-started
I looked into it for a while, the issue here is that the way the core library tries to determine the default project is by calling google.auth.default() and ignoring the credentials returned (https://github.com/googleapis/google-cloud-python/blob/master/core/google/cloud/_helpers.py#L186). But that method is mostly used to determine the credentials, so it throws an error if it doesn't find one in the environment (https://github.com/googleapis/google-auth-library-python/blob/master/google/auth/_default.py#L317). Maybe the fix is for google.auth to have a default_project() method that only looks for that? Or maybe more useful: a flag parameter in default() that is raise_missing_credentials?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.authtype: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.