Skip to content

Commit c2a171b

Browse files
authored
Fix: Fallback to the breaking change category if the model's query can't be rendered at parse time and the auto categorization mode is set to FULL (#1369)
1 parent 75c80cb commit c2a171b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

sqlmesh/core/plan/definition.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
from datetime import datetime
88
from enum import Enum
99

10-
from sqlmesh.core.config import CategorizerConfig, EnvironmentSuffixTarget
10+
from sqlmesh.core.config import (
11+
AutoCategorizationMode,
12+
CategorizerConfig,
13+
EnvironmentSuffixTarget,
14+
)
1115
from sqlmesh.core.console import SNAPSHOT_CHANGE_CATEGORY_STR
1216
from sqlmesh.core.context_diff import ContextDiff
1317
from sqlmesh.core.environment import Environment, EnvironmentNamingInfo
@@ -570,19 +574,19 @@ def _categorize_snapshots(self) -> None:
570574
model_with_missing_columns = downstream
571575
break
572576

577+
new, old = self.context_diff.modified_snapshots[model_name]
573578
if model_with_missing_columns is None:
574-
new, old = self.context_diff.modified_snapshots[model_name]
575579
change_category = categorize_change(
576580
new, old, config=self.categorizer_config
577581
)
578582
if change_category is not None:
579583
self.set_choice(new, change_category)
580584
else:
581-
logger.warning(
582-
"Changes to model '%s' cannot be automatically categorized due to missing schema for model '%s'",
583-
model_name,
584-
model_with_missing_columns,
585+
mode = self.categorizer_config.dict().get(
586+
new.model.source_type, AutoCategorizationMode.OFF
585587
)
588+
if mode == AutoCategorizationMode.FULL:
589+
self.set_choice(new, SnapshotChangeCategory.BREAKING)
586590

587591
# set to breaking if an indirect child has no directly modified parents
588592
# that need a decision. this can happen when a revert to a parent causes

tests/core/test_plan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def test_auto_categorization(make_snapshot, mocker: MockerFixture):
364364
def test_auto_categorization_missing_schema_downstream(make_snapshot, mocker: MockerFixture):
365365
snapshot = make_snapshot(SqlModel(name="a", query=parse_one("select 1, ds")))
366366
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
367-
updated_snapshot = make_snapshot(SqlModel(name="a", query=parse_one("select 2, ds")))
367+
updated_snapshot = make_snapshot(SqlModel(name="a", query=parse_one("select 1, 2, ds")))
368368

369369
downstream_snapshot = make_snapshot(
370370
SqlModel(name="b", query=parse_one("select * from tbl"), depends_on={"a"}),
@@ -389,8 +389,8 @@ def test_auto_categorization_missing_schema_downstream(make_snapshot, mocker: Mo
389389

390390
Plan(context_diff_mock)
391391

392-
assert updated_snapshot.version is None
393-
assert updated_snapshot.change_category is None
392+
assert updated_snapshot.version
393+
assert updated_snapshot.change_category == SnapshotChangeCategory.BREAKING
394394

395395

396396
def test_end_from_missing_instead_of_now(make_snapshot, mocker: MockerFixture):

0 commit comments

Comments
 (0)