From 93641ffa7af61c72c06440b59386caf000aeaf4e Mon Sep 17 00:00:00 2001 From: Mike Alfare <13974384+mikealfare@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:30:43 -0400 Subject: [PATCH] Verify that the behavior flag warning fires once (#916) * verify that the behavior flag warning fires once * remove dev req that is not needed --- .../unreleased/Fixes-20240920-184812.yaml | 6 +++ tests/functional/test_columns_in_relation.py | 44 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixes-20240920-184812.yaml diff --git a/.changes/unreleased/Fixes-20240920-184812.yaml b/.changes/unreleased/Fixes-20240920-184812.yaml new file mode 100644 index 000000000..754e9558a --- /dev/null +++ b/.changes/unreleased/Fixes-20240920-184812.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Restrict behavior change warnings to firing once per run to avoid noisy logs +time: 2024-09-20T18:48:12.064324-04:00 +custom: + Author: mikealfare + Issue: "915" diff --git a/tests/functional/test_columns_in_relation.py b/tests/functional/test_columns_in_relation.py index 60aeaa2aa..608217a41 100644 --- a/tests/functional/test_columns_in_relation.py +++ b/tests/functional/test_columns_in_relation.py @@ -1,5 +1,7 @@ +import os + from dbt.adapters.base import Column -from dbt.tests.util import run_dbt +from dbt.tests.util import run_dbt, run_dbt_and_capture import pytest from dbt.adapters.redshift import RedshiftRelation @@ -57,3 +59,43 @@ def expected_columns(self): Column(column="my_num", dtype="numeric", numeric_precision=3, numeric_scale=2), Column(column="my_char", dtype="varchar", char_size=1), ] + + +ONE_CHECK = """ +select 1 as id +-- {{ adapter.get_columns_in_relation(this) }} +""" + + +TWO_CHECK = """ +select 1 as id +-- {{ adapter.get_columns_in_relation(this) }} +-- {{ adapter.get_columns_in_relation(this) }} +""" + + +class TestBehaviorFlagFiresOnce: + @pytest.fixture(scope="class") + def project_config_update(self): + return {"flags": {"restrict_direct_pg_catalog_access": False}} + + @pytest.fixture(scope="class") + def models(self): + return {"one_check.sql": ONE_CHECK, "two_check.sql": TWO_CHECK} + + def test_warning_fires_once(self, project): + msg = "https://docs.getdbt.com/reference/global-configs/behavior-changes#redshift-restrict_direct_pg_catalog_access" + + # trigger the evaluation once, we get one warning + _, logs = run_dbt_and_capture(["--debug", "run", "--models", "one_check"]) + assert logs.count(msg) == 1 + + # trigger the evaluation twice, we still get one warning + _, logs = run_dbt_and_capture(["--debug", "run", "--models", "one_check"]) + assert logs.count(msg) == 1 + + # trigger the evaluation three times, across two models, we still get one warning + _, logs = run_dbt_and_capture(["--debug", "run", "--full-refresh"]) + assert logs.count(msg) == 1 + + # note, we still got a warning in the second call, so it's once per invocation