From c1b0bd8279eb99122e02273af9ac6d308409eddf Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Tue, 9 Sep 2025 14:49:52 -0700 Subject: [PATCH] Fix: Redundant creation of view models during the first evaluation --- sqlmesh/core/snapshot/evaluator.py | 9 +++++++-- tests/core/test_snapshot_evaluator.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sqlmesh/core/snapshot/evaluator.py b/sqlmesh/core/snapshot/evaluator.py index 3ed9c20765..961062fe45 100644 --- a/sqlmesh/core/snapshot/evaluator.py +++ b/sqlmesh/core/snapshot/evaluator.py @@ -50,7 +50,7 @@ CustomKind, ) from sqlmesh.core.model.kind import _Incremental -from sqlmesh.utils import CompletionStatus +from sqlmesh.utils import CompletionStatus, columns_to_types_all_known from sqlmesh.core.schema_diff import ( has_drop_alteration, TableAlterOperation, @@ -747,6 +747,11 @@ def _evaluate_snapshot( adapter.execute(model.render_pre_statements(**render_statements_kwargs)) if not target_table_exists or (model.is_seed and not snapshot.intervals): + columns_to_types_provided = ( + model.kind.is_materialized + and model.columns_to_types_ + and columns_to_types_all_known(model.columns_to_types_) + ) if self._can_clone(snapshot, deployability_index): self._clone_snapshot_in_dev( snapshot=snapshot, @@ -759,7 +764,7 @@ def _evaluate_snapshot( ) runtime_stage = RuntimeStage.EVALUATING target_table_exists = True - elif model.annotated or model.is_seed or model.kind.is_scd_type_2: + elif columns_to_types_provided or model.is_seed or model.kind.is_scd_type_2: self._execute_create( snapshot=snapshot, table_name=target_table_name, diff --git a/tests/core/test_snapshot_evaluator.py b/tests/core/test_snapshot_evaluator.py index 955c7f7859..6a39f600de 100644 --- a/tests/core/test_snapshot_evaluator.py +++ b/tests/core/test_snapshot_evaluator.py @@ -646,7 +646,7 @@ def test_evaluate_materialized_view( ) # Ensure that the materialized view is recreated even if it exists - assert adapter_mock.create_view.assert_called + assert adapter_mock.create_view.call_count == 1 def test_evaluate_materialized_view_with_partitioned_by_cluster_by(