Skip to content

Commit 27cbee2

Browse files
committed
Updated representativeness for indirect_non_breaking models to match deployability.
Signed-off-by: davem-bis <68955845+davem-bis@users.noreply.github.com>
1 parent 7bd09ef commit 27cbee2

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

sqlmesh/core/snapshot/definition.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,8 +1720,9 @@ def create(
17201720
# Similarly, if the model depends on past and the start date is not aligned with the
17211721
# model's start, we should consider this snapshot non-deployable.
17221722
this_deployable = False
1723+
17231724
if not snapshot.is_paused or (
1724-
snapshot.is_indirect_non_breaking and snapshot.intervals
1725+
not snapshot.is_indirect_non_breaking and snapshot.intervals
17251726
):
17261727
# This snapshot represents what's currently deployed in prod.
17271728
representative_shared_version_ids.add(node)

tests/core/test_snapshot.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,32 +2407,44 @@ def test_earliest_start_date(sushi_context: Context):
24072407

24082408

24092409
def test_deployability_index(make_snapshot):
2410+
# Breaking change - should be both representantive / deployable
24102411
snapshot_a = make_snapshot(SqlModel(name="a", query=parse_one("SELECT 1")))
24112412
snapshot_a.categorize_as(SnapshotChangeCategory.BREAKING)
24122413

2414+
# Forward only breaking change - cannot be representative / deployable due to forward only
24132415
snapshot_b = make_snapshot(SqlModel(name="b", query=parse_one("SELECT 1")))
24142416
snapshot_b.categorize_as(SnapshotChangeCategory.BREAKING, forward_only=True)
24152417
snapshot_b.parents = (snapshot_a.snapshot_id,)
24162418

2419+
# Indirect breaking - cannot be representative / deployable due to forward only non-deployable parent
24172420
snapshot_c = make_snapshot(SqlModel(name="c", query=parse_one("SELECT 1")))
24182421
snapshot_c.categorize_as(SnapshotChangeCategory.INDIRECT_BREAKING)
24192422
snapshot_c.parents = (snapshot_b.snapshot_id,)
24202423

2424+
# Indirect breaking - cannot be representative / deployable due to forward only non-deployable parent
24212425
snapshot_d = make_snapshot(SqlModel(name="d", query=parse_one("SELECT 1")))
24222426
snapshot_d.categorize_as(SnapshotChangeCategory.INDIRECT_BREAKING)
24232427
snapshot_d.parents = (snapshot_b.snapshot_id, snapshot_a.snapshot_id)
24242428

2429+
# Non breaking - representative / deployable due to no breaking changes
24252430
snapshot_e = make_snapshot(SqlModel(name="e", query=parse_one("SELECT 1")))
24262431
snapshot_e.categorize_as(SnapshotChangeCategory.NON_BREAKING)
24272432

2433+
# Indirect breaking - can be representative / deployable due to deployable parents
24282434
snapshot_f = make_snapshot(SqlModel(name="f", query=parse_one("SELECT 1")))
24292435
snapshot_f.categorize_as(SnapshotChangeCategory.INDIRECT_BREAKING)
24302436
snapshot_f.parents = (snapshot_e.snapshot_id, snapshot_a.snapshot_id)
24312437

2438+
# Indirect non breaking - cannot be representative / deployable due to possible data drift from prod
24322439
snapshot_g = make_snapshot(SqlModel(name="g", query=parse_one("SELECT 1")))
24332440
snapshot_g.intervals = [(to_timestamp("2023-01-01"), to_timestamp("2023-01-02"))]
24342441
snapshot_g.categorize_as(SnapshotChangeCategory.INDIRECT_NON_BREAKING)
24352442
snapshot_g.parents = (snapshot_e.snapshot_id,)
2443+
2444+
# Indirect breaking - cannot be representative / deployable due to indirect non breaking non-deployable parent
2445+
snapshot_h = make_snapshot(SqlModel(name="h", query=parse_one("SELECT 1")))
2446+
snapshot_h.categorize_as(SnapshotChangeCategory.INDIRECT_BREAKING)
2447+
snapshot_h.parents = (snapshot_g.snapshot_id,)
24362448

24372449
snapshots = {
24382450
s.snapshot_id: s
@@ -2444,6 +2456,7 @@ def test_deployability_index(make_snapshot):
24442456
snapshot_e,
24452457
snapshot_f,
24462458
snapshot_g,
2459+
snapshot_h,
24472460
]
24482461
}
24492462

@@ -2452,18 +2465,20 @@ def test_deployability_index(make_snapshot):
24522465
assert deployability_index.is_deployable(snapshot_a)
24532466
assert deployability_index.is_deployable(snapshot_e)
24542467
assert deployability_index.is_deployable(snapshot_f)
2455-
assert not deployability_index.is_deployable(snapshot_g)
24562468
assert not deployability_index.is_deployable(snapshot_b)
24572469
assert not deployability_index.is_deployable(snapshot_c)
24582470
assert not deployability_index.is_deployable(snapshot_d)
2471+
assert not deployability_index.is_deployable(snapshot_g)
2472+
assert not deployability_index.is_deployable(snapshot_h)
24592473

24602474
assert deployability_index.is_representative(snapshot_a)
24612475
assert deployability_index.is_representative(snapshot_e)
24622476
assert deployability_index.is_representative(snapshot_f)
2463-
assert deployability_index.is_representative(snapshot_g)
24642477
assert not deployability_index.is_representative(snapshot_b)
24652478
assert not deployability_index.is_representative(snapshot_c)
24662479
assert not deployability_index.is_representative(snapshot_d)
2480+
assert not deployability_index.is_representative(snapshot_g)
2481+
assert not deployability_index.is_representative(snapshot_h)
24672482

24682483
all_deployable_index = deployability_index.all_deployable()
24692484
assert all(all_deployable_index.is_deployable(s) for s in snapshots.values())

0 commit comments

Comments
 (0)