diff --git a/sqlmesh/dbt/model.py b/sqlmesh/dbt/model.py index e34e66e119..4cbca09aee 100644 --- a/sqlmesh/dbt/model.py +++ b/sqlmesh/dbt/model.py @@ -257,13 +257,6 @@ def model_kind(self, context: DbtContext) -> ModelKind: if field_val is not None: incremental_by_kind_kwargs[field] = field_val - disable_restatement = self.disable_restatement - if disable_restatement is None: - disable_restatement = ( - not self.full_refresh if self.full_refresh is not None else False - ) - incremental_kind_kwargs["disable_restatement"] = disable_restatement - if self.time_column: strategy = self.incremental_strategy or target.default_incremental_strategy( IncrementalByTimeRangeKind @@ -277,11 +270,20 @@ def model_kind(self, context: DbtContext) -> ModelKind: return IncrementalByTimeRangeKind( time_column=self.time_column, + disable_restatement=( + self.disable_restatement if self.disable_restatement is not None else False + ), auto_restatement_intervals=self.auto_restatement_intervals, **incremental_kind_kwargs, **incremental_by_kind_kwargs, ) + disable_restatement = self.disable_restatement + if disable_restatement is None: + disable_restatement = ( + not self.full_refresh if self.full_refresh is not None else False + ) + if self.unique_key: strategy = self.incremental_strategy or target.default_incremental_strategy( IncrementalByUniqueKeyKind @@ -307,6 +309,7 @@ def model_kind(self, context: DbtContext) -> ModelKind: return IncrementalByUniqueKeyKind( unique_key=self.unique_key, + disable_restatement=disable_restatement, **incremental_kind_kwargs, **incremental_by_kind_kwargs, ) @@ -316,6 +319,7 @@ def model_kind(self, context: DbtContext) -> ModelKind: ) return IncrementalUnmanagedKind( insert_overwrite=strategy in INCREMENTAL_BY_TIME_STRATEGIES, + disable_restatement=disable_restatement, **incremental_kind_kwargs, ) if materialization == Materialization.EPHEMERAL: diff --git a/tests/dbt/test_transformation.py b/tests/dbt/test_transformation.py index e483e45ae1..809e28fba4 100644 --- a/tests/dbt/test_transformation.py +++ b/tests/dbt/test_transformation.py @@ -259,7 +259,7 @@ def test_model_kind(): incremental_strategy="merge", full_refresh=False, ).model_kind(context) == IncrementalByTimeRangeKind( - time_column="foo", dialect="duckdb", forward_only=True, disable_restatement=True + time_column="foo", dialect="duckdb", forward_only=True, disable_restatement=False ) assert ModelConfig(