-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backport combo of prs 955 and 957 (#958)
- Loading branch information
1 parent
71e1290
commit 03437d5
Showing
3 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/functional/adapter/query_comment_test/test_job_label.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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" |