Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify that the behavior flag warning fires once #916

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading