Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit b3eeb08

Browse files
authored
Fix refresh_strategy = auto semantics for dynamic tables (#1268)
* Add failing test. * Parametrize cases * Change comparison logic for when to rebuild if DT has auto refresh strategy (implicit or explicit). * Add changelog --------- Co-authored-by: VersusFacit <[email protected]>
1 parent 457c361 commit b3eeb08

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: AUTO should no longer lead to rebuilds of dynamic tables.
3+
time: 2024-12-09T13:15:30.554566-08:00
4+
custom:
5+
Author: versusfacit
6+
Issue: "1267"

dbt/adapters/snowflake/relation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from dbt_common.events.functions import fire_event, warn_or_error
1818

1919
from dbt.adapters.snowflake.relation_configs import (
20+
RefreshMode,
2021
SnowflakeCatalogConfigChange,
2122
SnowflakeDynamicTableConfig,
2223
SnowflakeDynamicTableConfigChangeset,
@@ -109,7 +110,10 @@ def dynamic_table_config_changeset(
109110
)
110111
)
111112

112-
if new_dynamic_table.refresh_mode != existing_dynamic_table.refresh_mode:
113+
if (
114+
new_dynamic_table.refresh_mode != RefreshMode.AUTO
115+
and new_dynamic_table.refresh_mode != existing_dynamic_table.refresh_mode
116+
):
113117
config_change_collection.refresh_mode = SnowflakeDynamicTableRefreshModeConfigChange(
114118
action=RelationConfigChangeAction.create,
115119
context=new_dynamic_table.refresh_mode,

dbt/adapters/snowflake/relation_configs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
SnowflakeCatalogConfigChange,
44
)
55
from dbt.adapters.snowflake.relation_configs.dynamic_table import (
6+
RefreshMode,
67
SnowflakeDynamicTableConfig,
78
SnowflakeDynamicTableConfigChangeset,
89
SnowflakeDynamicTableRefreshModeConfigChange,

tests/functional/relation_tests/dynamic_table_tests/models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@
1717
"""
1818

1919

20+
EXPLICIT_AUTO_DYNAMIC_TABLE = """
21+
{{ config(
22+
materialized='dynamic_table',
23+
snowflake_warehouse='DBT_TESTING',
24+
target_lag='2 minutes',
25+
refresh_mode='AUTO',
26+
) }}
27+
select * from {{ ref('my_seed') }}
28+
"""
29+
30+
IMPLICIT_AUTO_DYNAMIC_TABLE = """
31+
{{ config(
32+
materialized='dynamic_table',
33+
snowflake_warehouse='DBT_TESTING',
34+
target_lag='2 minutes',
35+
) }}
36+
select * from {{ ref('my_seed') }}
37+
"""
38+
39+
2040
DYNAMIC_TABLE_DOWNSTREAM = """
2141
{{ config(
2242
materialized='dynamic_table',

tests/functional/relation_tests/dynamic_table_tests/test_basic.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from dbt.tests.util import run_dbt
3+
from dbt.tests.util import assert_message_in_logs, run_dbt, run_dbt_and_capture
44

55
from tests.functional.relation_tests.dynamic_table_tests import models
66
from tests.functional.utils import query_relation_type
@@ -46,3 +46,44 @@ class TestBasicIcebergOn(TestBasic):
4646
@pytest.fixture(scope="class")
4747
def project_config_update(self):
4848
return {"flags": {"enable_iceberg_materializations": True}}
49+
50+
51+
class TestAutoConfigDoesntFullRefresh:
52+
"""
53+
AUTO refresh_strategy will be compared accurately with both INCREMENTAL and FULL.
54+
https://github.com/dbt-labs/dbt-snowflake/issues/1267
55+
"""
56+
57+
DT_NAME = "my_dynamic_table"
58+
59+
@pytest.fixture(scope="class", autouse=True)
60+
def seeds(self):
61+
return {"my_seed.csv": models.SEED}
62+
63+
@pytest.fixture(scope="class", autouse=True)
64+
def models(self):
65+
yield {
66+
f"explicit_{self.DT_NAME}.sql": models.EXPLICIT_AUTO_DYNAMIC_TABLE,
67+
f"implicit_{self.DT_NAME}.sql": models.IMPLICIT_AUTO_DYNAMIC_TABLE,
68+
}
69+
70+
@pytest.mark.parametrize("test_dt", [f"explicit_{DT_NAME}", f"implicit_{DT_NAME}"])
71+
def test_auto_config_doesnt_full_refresh(self, project, test_dt):
72+
model_qualified_name = f"{project.database}.{project.test_schema}.{test_dt}"
73+
74+
run_dbt(["seed"])
75+
_, logs = run_dbt_and_capture(["--debug", "run", "--select", f"{test_dt}.sql"])
76+
assert_message_in_logs(f"create dynamic table {model_qualified_name}", logs)
77+
assert_message_in_logs("refresh_mode = AUTO", logs)
78+
79+
_, logs = run_dbt_and_capture(["--debug", "run", "--select", f"{test_dt}.sql"])
80+
81+
assert_message_in_logs(f"create dynamic table {model_qualified_name}", logs, False)
82+
assert_message_in_logs(
83+
f"create or replace dynamic table {model_qualified_name}", logs, False
84+
)
85+
assert_message_in_logs("refresh_mode = AUTO", logs, False)
86+
assert_message_in_logs(
87+
f"No configuration changes were identified on: `{model_qualified_name}`. Continuing.",
88+
logs,
89+
)

0 commit comments

Comments
 (0)