Skip to content

Commit 001899c

Browse files
authored
Fix: Unpaused snapshots that are downstream of snapshots with enabled auto-restatement can still be representative (#3584)
1 parent 2319c80 commit 001899c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

sqlmesh/core/snapshot/definition.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,10 @@ def _visit(node: SnapshotId, deployable: bool = True) -> None:
14361436
)
14371437
else:
14381438
this_deployable, children_deployable = False, False
1439-
representative_shared_version_ids.discard(node)
1439+
if node in snapshots and not snapshots[node].is_paused:
1440+
representative_shared_version_ids.add(node)
1441+
else:
1442+
representative_shared_version_ids.discard(node)
14401443

14411444
deployability_mapping[node] = deployability_mapping.get(node, True) and this_deployable
14421445
for child in reversed_dag[node]:

tests/core/test_snapshot.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,43 @@ def test_deployability_index_unpaused_forward_only(make_snapshot):
17321732
assert deplyability_index.is_representative(snapshot_b)
17331733

17341734

1735+
def test_deployability_index_unpaused_auto_restatement(make_snapshot):
1736+
model_a = SqlModel(
1737+
name="a",
1738+
query=parse_one("SELECT 1, ds"),
1739+
kind=IncrementalByTimeRangeKind(
1740+
time_column="ds", forward_only=True, auto_restatement_cron="@weekly"
1741+
),
1742+
)
1743+
snapshot_a = make_snapshot(model_a)
1744+
snapshot_a.categorize_as(SnapshotChangeCategory.FORWARD_ONLY)
1745+
snapshot_a.unpaused_ts = 1
1746+
1747+
# Snapshot B is a child of a model with auto restatement and is not paused,
1748+
# so it is not deployable but is representative
1749+
snapshot_b = make_snapshot(SqlModel(name="b", query=parse_one("SELECT 1")))
1750+
snapshot_b.categorize_as(SnapshotChangeCategory.BREAKING)
1751+
snapshot_b.parents = (snapshot_a.snapshot_id,)
1752+
snapshot_b.unpaused_ts = 1
1753+
1754+
# Snapshot C is paused and hence is neither deployable nor representative
1755+
snapshot_c = make_snapshot(SqlModel(name="c", query=parse_one("SELECT 1")))
1756+
snapshot_c.categorize_as(SnapshotChangeCategory.BREAKING)
1757+
snapshot_c.parents = (snapshot_b.snapshot_id,)
1758+
1759+
deplyability_index = DeployabilityIndex.create(
1760+
{s.snapshot_id: s for s in [snapshot_a, snapshot_b, snapshot_c]}
1761+
)
1762+
1763+
assert not deplyability_index.is_deployable(snapshot_a)
1764+
assert not deplyability_index.is_deployable(snapshot_b)
1765+
assert not deplyability_index.is_deployable(snapshot_c)
1766+
1767+
assert deplyability_index.is_representative(snapshot_a)
1768+
assert deplyability_index.is_representative(snapshot_b)
1769+
assert not deplyability_index.is_representative(snapshot_c)
1770+
1771+
17351772
def test_deployability_index_uncategorized_forward_only_model(make_snapshot):
17361773
model_a = SqlModel(
17371774
name="a",

0 commit comments

Comments
 (0)