-
Notifications
You must be signed in to change notification settings - Fork 156
fix(dryrun): Run authenticated dryrun queries in mozdata rather than the target project
#9845
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,14 +148,18 @@ def __init__( | |
| self.project = project | ||
| self.dataset = dataset | ||
| self.table = table | ||
| self.billing_project = billing_project | ||
| # if using cloud function and billing project isn't set, randomly select project to use | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: the comment now only describes the |
||
| self.billing_project = ( | ||
| billing_project | ||
| if billing_project or not use_cloud_function | ||
| else random.choice( | ||
| ConfigLoader.get("dry_run", "default_projects", fallback=[None]) | ||
| if not self.billing_project: | ||
| self.billing_project = ( | ||
| random.choice( | ||
| ConfigLoader.get( | ||
| "dry_run", "cloud_function_billing_projects", fallback=[None] | ||
| ) | ||
| ) | ||
| if use_cloud_function | ||
| else ConfigLoader.get("dry_run", "default_billing_project") | ||
This comment was marked as outdated.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Rather than basing the workaround on whether a target is active, I opted to specify the billing project when doing deploys. What do you think now @claude? |
||
| ) | ||
| ) | ||
| try: | ||
| self.metadata = Metadata.of_query_file(self.sqlfile) | ||
| except FileNotFoundError: | ||
|
|
@@ -474,17 +478,15 @@ def dry_run_result(self): | |
| ) | ||
| result = json.load(r) | ||
| else: | ||
| # Prefer billing project if provided, otherwise use the project from the SQL file | ||
| self.client.project = ( | ||
| self.billing_project if self.billing_project else project | ||
| ) | ||
| job_config = bigquery.QueryJobConfig( | ||
| dry_run=True, | ||
| use_query_cache=False, | ||
| default_dataset=f"{project}.{dataset}", | ||
| query_parameters=query_parameters, | ||
| ) | ||
| job = self.client.query(sql, job_config=job_config) | ||
| job = self.client.query( | ||
| sql, job_config=job_config, project=self.billing_project | ||
| ) | ||
| try: | ||
| dataset_labels = self.client.get_dataset(job.default_dataset).labels | ||
| except Exception as e: | ||
|
|
||
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.
suggestion: this
(<artifact project> if not use_cloud_function else None)expression is now duplicated at three deploy call sites — here,bigquery_etl/cli/deploy.py:1280, andbigquery_etl/deploy.py:107— and each derives the project differently (extract_from_query_pathhere vs.file_path.parent.parent.parent.namein the other two).Since correct
--targetbehaviour now depends on every authenticated dry run in the deploy path carrying this argument, a future deploy-path dry run that omits it will silently bill tomozdataand 403 for sandbox service accounts. Consider a single helper (e.g.dryrun_billing_project(project, use_cloud_function)inbigquery_etl/dryrun.py) that the three sites call, so the policy lives in one place.