Skip to content

Commit bcb0eb4

Browse files
committed
FO model partition changes are breaking not FO
1 parent e24c9da commit bcb0eb4

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

sqlmesh/core/plan/builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ def _is_forward_only_change(self, s_id: SnapshotId) -> bool:
717717
# If the model kind has changed, then we should not consider this to be a forward-only change.
718718
if snapshot.is_model and old.model.kind.name != snapshot.model.kind.name:
719719
return False
720+
if snapshot.is_model and old.model.partitioned_by != snapshot.model.partitioned_by:
721+
return False
720722
return (
721723
snapshot.is_model
722724
and snapshot.model.forward_only

tests/core/test_plan.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,49 @@ def test_forward_only_models_model_kind_changed(make_snapshot, mocker: MockerFix
17241724
assert updated_snapshot.change_category == SnapshotChangeCategory.BREAKING
17251725

17261726

1727+
def test_forward_only_models_partition_changed(make_snapshot, mocker: MockerFixture):
1728+
snapshot = make_snapshot(
1729+
SqlModel(
1730+
name="a",
1731+
query=parse_one("select 3, ds, ds2"),
1732+
kind=IncrementalByTimeRangeKind(time_column="ds", forward_only=True),
1733+
partitioned_by=[parse_one("ds")],
1734+
)
1735+
)
1736+
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
1737+
updated_snapshot = make_snapshot(
1738+
SqlModel(
1739+
name="a",
1740+
query=parse_one("select 3, ds, ds2"),
1741+
kind=IncrementalByTimeRangeKind(time_column="ds", forward_only=True),
1742+
partitioned_by=[parse_one("ds2")],
1743+
)
1744+
)
1745+
updated_snapshot.previous_versions = snapshot.all_versions
1746+
1747+
context_diff = ContextDiff(
1748+
environment="test_environment",
1749+
is_new_environment=True,
1750+
is_unfinalized_environment=False,
1751+
normalize_environment_name=True,
1752+
create_from="prod",
1753+
create_from_env_exists=True,
1754+
added=set(),
1755+
removed_snapshots={},
1756+
modified_snapshots={updated_snapshot.name: (updated_snapshot, snapshot)},
1757+
snapshots={updated_snapshot.snapshot_id: updated_snapshot},
1758+
new_snapshots={updated_snapshot.snapshot_id: updated_snapshot},
1759+
previous_plan_id=None,
1760+
previously_promoted_snapshot_ids=set(),
1761+
previous_finalized_snapshots=None,
1762+
previous_gateway_managed_virtual_layer=False,
1763+
gateway_managed_virtual_layer=False,
1764+
)
1765+
1766+
PlanBuilder(context_diff, DuckDBEngineAdapter.SCHEMA_DIFFER, is_dev=True).build()
1767+
assert updated_snapshot.change_category == SnapshotChangeCategory.BREAKING
1768+
1769+
17271770
def test_indirectly_modified_forward_only_model(make_snapshot, mocker: MockerFixture):
17281771
snapshot_a = make_snapshot(SqlModel(name="a", query=parse_one("select 1 as a, ds")))
17291772
snapshot_a.categorize_as(SnapshotChangeCategory.BREAKING)

0 commit comments

Comments
 (0)