From 8c0a7f4f217af3466a0c171796aef150a330adb7 Mon Sep 17 00:00:00 2001 From: Matthew McKnight <91097623+McKnight-42@users.noreply.github.com> Date: Fri, 6 Oct 2023 14:51:41 -0500 Subject: [PATCH] Revert "[fix] Use rendered query comment for job labels (#955)" This reverts commit d5b4114ca1ef28d3c2bd3c61812e3a2c901a2366. --- .../unreleased/Fixes-20231005-235950.yaml | 6 --- dbt/adapters/bigquery/connections.py | 5 +- .../query_comment_test/test_job_label.py | 52 ------------------- 3 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 .changes/unreleased/Fixes-20231005-235950.yaml delete mode 100644 tests/functional/adapter/query_comment_test/test_job_label.py diff --git a/.changes/unreleased/Fixes-20231005-235950.yaml b/.changes/unreleased/Fixes-20231005-235950.yaml deleted file mode 100644 index bf0bf6fa6..000000000 --- a/.changes/unreleased/Fixes-20231005-235950.yaml +++ /dev/null @@ -1,6 +0,0 @@ -kind: Fixes -body: Fix issue where job labels are not rendered when using macro for query comment -time: 2023-10-05T23:59:50.077842+02:00 -custom: - Author: kodaho mikealfare - Issue: "863" diff --git a/dbt/adapters/bigquery/connections.py b/dbt/adapters/bigquery/connections.py index 1e96ed5ef..a5c7b9355 100644 --- a/dbt/adapters/bigquery/connections.py +++ b/dbt/adapters/bigquery/connections.py @@ -451,10 +451,9 @@ def raw_execute( hasattr(self.profile, "query_comment") and self.profile.query_comment and self.profile.query_comment.job_label - and self.query_header - and (query_comment := self.query_header.comment.query_comment) ): - labels = self._labels_from_query_comment(query_comment) + query_comment = self.profile.query_comment + labels = self._labels_from_query_comment(query_comment.comment) else: labels = {} diff --git a/tests/functional/adapter/query_comment_test/test_job_label.py b/tests/functional/adapter/query_comment_test/test_job_label.py deleted file mode 100644 index af984a8c4..000000000 --- a/tests/functional/adapter/query_comment_test/test_job_label.py +++ /dev/null @@ -1,52 +0,0 @@ -import pytest - -from google.cloud.bigquery.client import Client - -from dbt.tests.util import run_dbt - - -_MACRO__BQ_LABELS = """ -{% macro bq_labels() %}{ - "system": "{{ env_var('LABEL_SYSTEM', 'my_system') }}", - "env_type": "{{ env_var('LABEL_ENV', 'dev') }}" -}{% endmacro %} -""" -_MODEL__MY_TABLE = """ -{{ config(materialized= "table") }} -select 1 as id -""" - - -class TestQueryCommentJobLabel: - @pytest.fixture(scope="class") - def models(self): - return {"my_table.sql": _MODEL__MY_TABLE} - - @pytest.fixture(scope="class") - def macros(self): - return {"bq_labels.sql": _MACRO__BQ_LABELS} - - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "query-comment": { - "comment": "{{ bq_labels() }}", - "job-label": True, - "append": True, - } - } - - def test_query_comments_displays_as_job_labels(self, project): - """ - Addresses this regression in dbt-bigquery 1.6: - https://github.com/dbt-labs/dbt-bigquery/issues/863 - """ - results = run_dbt(["run"]) - job_id = results.results[0].adapter_response.get("job_id") - with project.adapter.connection_named("_test"): - client: Client = project.adapter.connections.get_thread_connection().handle - job = client.get_job(job_id=job_id) - - # this is what should happen - assert job.labels.get("system") == "my_system" - assert job.labels.get("env_type") == "dev"