Skip to content

Commit

Permalink
Verify that the behavior flag warning fires once (#916)
Browse files Browse the repository at this point in the history
* verify that the behavior flag warning fires once
* remove dev req that is not needed
  • Loading branch information
mikealfare authored Oct 16, 2024
1 parent 0b02178 commit 93641ff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240920-184812.yaml
Original file line number Diff line number Diff line change
@@ -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"
44 changes: 43 additions & 1 deletion tests/functional/test_columns_in_relation.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 93641ff

Please sign in to comment.