Skip to content
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

[fix] Use rendered query comment for job labels #955

Merged
merged 4 commits into from
Oct 6, 2023

Conversation

kodaho
Copy link
Contributor

@kodaho kodaho commented Oct 5, 2023

resolves #863

Problem

A regression appears in the last release of dbt-bigquery. A user can previously add labels to a BigQuery job thanks to a macro returning a mapping. In the version 1.6.0, this was no longer possible even if the project is set to activate this feature.

Solution

The proposed solution is to use, instead of self.profile.query_comment (which is the not-rendered Jinja macro), self.query_header.comment.query_comment (the JSON rendered query comments).

I added some safeguards to make sure that self.query_header.comment.query_comment is not null but during the runtime, it should never be the case because of the following succession of functions and methods calls during a run command:

  1. The query labels are sent with a run command, command decorated with the decorator requires.manifest.
  2. The class method ManifestLoader.get_full_manifest is called.
  3. The method ManifestLoader().save_macros_to_adapter is called.
  4. ManifestLoader().macro_hook is called, knowing that macro_hook = adapter.connections.set_query_header.
  5. Calling Connection().set_query_header makes sure that self.query_header is not null.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@kodaho kodaho requested a review from a team as a code owner October 5, 2023 21:14
@kodaho kodaho requested a review from McKnight-42 October 5, 2023 21:14
@cla-bot
Copy link

cla-bot bot commented Oct 5, 2023

Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA.

In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR.

CLA has not been signed by users: @kodaho

@kodaho kodaho marked this pull request as draft October 5, 2023 21:17
@cla-bot cla-bot bot added the cla:yes label Oct 5, 2023
@kodaho kodaho marked this pull request as ready for review October 5, 2023 21:26
@kodaho kodaho marked this pull request as draft October 5, 2023 21:41
@kodaho kodaho marked this pull request as ready for review October 5, 2023 22:01
@dbeatty10 dbeatty10 added the ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering label Oct 5, 2023
@McKnight-42 McKnight-42 closed this Oct 6, 2023
@McKnight-42 McKnight-42 reopened this Oct 6, 2023
@McKnight-42 McKnight-42 merged commit d5b4114 into dbt-labs:main Oct 6, 2023
52 checks passed
@McKnight-42
Copy link
Contributor

@kodaho thank you for contributing this was working on something locally. It was a fantastic pull in updating the test as well.

McKnight-42 pushed a commit that referenced this pull request Oct 6, 2023
* [fix] Use rendered query comment for job labels

* Add test from dbt-labs/dbt-query#872

* Valid JSON in test

* Add changie entry
@McKnight-42 McKnight-42 mentioned this pull request Oct 6, 2023
4 tasks
McKnight-42 added a commit that referenced this pull request Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes ok to test ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ADAP-769] [Regression] bq jobs labeling doesn't work on 1.6.0
3 participants