-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise DbtProfileError on invalid default credential #40
Conversation
Hey @jtcohen6, thanks for the pointers on the issue. Have a couple of beginner questions if you don't mind :P Logging stuffTrying to understand logging things to stdout a bit more and using logger.info(">>>>> OUTSIDE")
@lru_cache()
def get_bigquery_defaults(scopes=None) -> Tuple[Any, Optional[str]]:
"""
Returns (credentials, project_id)
project_id is returned available from the environment; otherwise None
"""
# Cached, because the underlying implementation shells out, taking ~1s
logger.info(">>>>> INSIDE")
try:
logger.info(">>>>> INNER")
credentials, _ = google.auth.default(scopes=scopes)
return credentials, _
except google.auth.exceptions.DefaultCredentialsError as e:
raise DbtProfileError(INVALID_PROFILE_MESSAGE.format(error_string=e)) On an invalid bq project in Running with dbt=1.0.0-b1
>>>>> OUTSIDE
>>>>> INSIDE
>>>>> INNER
No profile "bigquery" found, continuing with no target
Installing dbt-labs/dbt_utils@0.7.3
Installed from version 0.7.3
Up to date! But on a valid project, the output is as follows where I don't see the other Running with dbt=1.0.0-b1
>>>>> OUTSIDE
Installing dbt-labs/dbt_utils@0.7.3
Installed from version 0.7.3
Up to date! Guessing it has nothing to do with where I placed Adding testsHow would I go about adding a test to this? I can see an
And a couple of dbt-bigquery/tests/integration/base.py Line 395 in 5486d04
Should I copy
And that's about what I grokked... (tbh, I don't really know how to run the bq tests locally 🤦 ). Thanks again @jtcohen6 🙌 |
Added a deps test but almost certain it doesn't actually test what we want it to test... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremyyeo Thanks for the contribution! This change looks good to me.
It's going to be tricky to test this in CI, since we don't use gcloud
-based connection methods for any integration tests. The ideal would be a unit test that ensures
get_bigquery_defaults
will return either successful credentials (as a tuple), or raise a DbtProfileError
... but I think we may have to rely on local testing for this one.
Speaking of which, have you been able to actually reproduce the error reported in #27, when running dbt deps
without this change?
I just tried (using dbt-bigquery==0.21.0
, after running gcloud config unset project
), and it looks to me like dbt deps
succeeds while dbt run
fails with a different version of the error:
ERROR: Database Error
Project was not passed and could not be determined from the environment.
In any case, it is documented that google.auth.default
will return DefaultCredentialsError
if no credentials are found, or if the default credentials are invalid—so I think catching and wrapping that exception as a DbtProfileError
is technically correct and an uncontroversial improvement over the status quo.
Note I didn't use the On ✅ (A) A nonsense # ~/.dbt/profiles.yml
bigquery:
outputs:
dev:
type: bigquery
method: service-account
project: anonsensicalprojectthatdoesntexist
dataset: sandbox_dataset
threads: 1
keyfile: /path_to_my_keyfile/gcp_service_keyfile.json
timeout_seconds: 300
priority: interactive
retries: 1
target: dev
✅ (B) Setting a target that doesn't exists:
But not with: ❌ (C) Commenting out the # ~/.dbt/profiles.yml
bigquery:
outputs:
dev:
type: bigquery
method: service-account
dataset: sandbox_dataset
threads: 1
keyfile: /path_to_my_keyfile/gcp_service_keyfile.json
timeout_seconds: 300
priority: interactive
retries: 1
target: dev
Pretty strange... or maybe expected... perhaps in parsing the Should we still merge this (after removing my non test 😂 ) to handle case (C) and as you pointed out that it is documented that |
Actually expected! This was a feature introduced in v0.19 that allows you to fall back to your "default project," configured via Hence, issue #27.
Yes! & no need for another PR to do the key checking, given the background above. Can you confirm that, with the setup in case (C) and using the changes in this PR, you're able to run |
@jeremyyeo Love it! I'm going to rebase this branch against |
ff60ad9
to
751a18e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the contribution, JerYeo! :)
* raise profile error * add deps test * remove test * Add changelog entry Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
Resolves #27
Description
Resolves the issue of dbt unable to install packages if a bigquery profile is invalid as per the issue linked.
Checklist
CHANGELOG.md
and added information about my change to the "dbt-bigquery next" section.