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

Commit 64e042a

Browse files
authored
ADAP-1017: Fix configuration change monitoring for scenarios with no changes (#1009)
* changie * add a test demonstrating the issue * check that the change collection has changes instead of checking that it exists * remove the partition config value from the config change since it is not hashable
1 parent 548d532 commit 64e042a

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Fixes
2+
body: Fixed issue where materialized views were failing on re-run with minimal config
3+
parameters
4+
time: 2023-11-07T17:43:52.972135-05:00
5+
custom:
6+
Author: "mikealfare"
7+
Issue: "1007"

dbt/adapters/bigquery/relation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ def materialized_view_config_changeset(
8484
)
8585

8686
if new_materialized_view.partition != existing_materialized_view.partition:
87+
# the existing PartitionConfig is not hashable, but since we need to do
88+
# a full refresh either way, we don't need to provide a context
8789
config_change_collection.partition = BigQueryPartitionConfigChange(
8890
action=RelationConfigChangeAction.alter,
89-
context=new_materialized_view.partition,
9091
)
9192

9293
if new_materialized_view.cluster != existing_materialized_view.cluster:
@@ -95,7 +96,7 @@ def materialized_view_config_changeset(
9596
context=new_materialized_view.cluster,
9697
)
9798

98-
if config_change_collection:
99+
if config_change_collection.has_changes:
99100
return config_change_collection
100101
return None
101102

dbt/adapters/bigquery/relation_configs/_partition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def parse_bq_table(cls, table: BigQueryTable) -> Dict[str, Any]:
152152

153153
@dataclass(frozen=True, eq=True, unsafe_hash=True)
154154
class BigQueryPartitionConfigChange(RelationConfigChange):
155-
context: Optional[PartitionConfig]
155+
context: Optional[Any] = None
156156

157157
@property
158158
def requires_full_refresh(self) -> bool:

tests/functional/adapter/materialized_view_tests/_files.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,14 @@
6767
record_valid_date
6868
from {{ ref('my_seed') }}
6969
"""
70+
71+
72+
MY_MINIMAL_MATERIALIZED_VIEW = """
73+
{{
74+
config(
75+
materialized = 'materialized_view',
76+
)
77+
}}
78+
79+
select * from {{ ref('my_seed') }}
80+
"""

tests/functional/adapter/materialized_view_tests/test_materialized_view.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dbt.tests.adapter.materialized_view.basic import MaterializedViewBasic
55

66
from tests.functional.adapter.materialized_view_tests._mixin import BigQueryMaterializedViewMixin
7+
from tests.functional.adapter.materialized_view_tests import _files
78

89

910
class TestBigqueryMaterializedViewsBasic(BigQueryMaterializedViewMixin, MaterializedViewBasic):
@@ -27,3 +28,26 @@ def test_materialized_view_only_updates_after_refresh(
2728
self, project, my_materialized_view, my_seed
2829
):
2930
pass
31+
32+
33+
class TestMaterializedViewRerun:
34+
"""
35+
This addresses: https://github.com/dbt-labs/dbt-bigquery/issues/1007
36+
37+
This effectively tests that defaults get properly set so that the run is idempotent.
38+
If the defaults are not properly set, changes could appear when there are no changes
39+
and cause unexpected scenarios.
40+
"""
41+
42+
@pytest.fixture(scope="class", autouse=True)
43+
def models(self):
44+
return {"my_minimal_materialized_view.sql": _files.MY_MINIMAL_MATERIALIZED_VIEW}
45+
46+
@pytest.fixture(scope="class", autouse=True)
47+
def seeds(self):
48+
return {"my_seed.csv": _files.MY_SEED}
49+
50+
def test_minimal_materialized_view_is_idempotent(self, project):
51+
run_dbt(["seed"])
52+
run_dbt(["run"])
53+
run_dbt(["run"])

0 commit comments

Comments
 (0)