Skip to content

Commit

Permalink
verify that the behavior flag warning fires once
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Sep 20, 2024
1 parent fb1b5ae commit f05d5b4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
git+https://github.com/dbt-labs/dbt-core.git#subdirectory=core
git+https://github.com/dbt-labs/dbt-adapters.git
git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter
git+https://github.com/dbt-labs/dbt-common.git
git+https://github.com/dbt-labs/dbt-common.git@behavior-flags-fire-once
git+https://github.com/dbt-labs/dbt-postgres.git

# dev
Expand All @@ -16,6 +16,7 @@ pytest~=7.4
pytest-csv~=3.0
pytest-dotenv~=0.5.2
pytest-logbook~=1.2
pytest-mock
pytest-xdist~=3.5
tox~=4.16

Expand Down
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 f05d5b4

Please sign in to comment.