Skip to content

Commit 6d00e35

Browse files
authored
Fix: Reporting deletion of physical tables for snapshots of symbolic / audit models (#5422)
1 parent d41c3e0 commit 6d00e35

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,12 @@ def cleanup(
518518
target_snapshots: Snapshots to cleanup.
519519
on_complete: A callback to call on each successfully deleted database object.
520520
"""
521+
target_snapshots = [
522+
t for t in target_snapshots if t.snapshot.is_model and not t.snapshot.is_symbolic
523+
]
521524
snapshots_to_dev_table_only = {
522525
t.snapshot.snapshot_id: t.dev_table_only for t in target_snapshots
523526
}
524-
525527
with self.concurrent_context():
526528
concurrent_apply_to_snapshots(
527529
[t.snapshot for t in target_snapshots],

tests/core/test_snapshot_evaluator.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,14 @@ def create_and_cleanup(name: str, dev_table_only: bool):
436436
snapshot.categorize_as(SnapshotChangeCategory.BREAKING, forward_only=True)
437437
snapshot.version = "test_version"
438438

439+
on_cleanup_mock = mocker.Mock()
440+
439441
evaluator.promote([snapshot], EnvironmentNamingInfo(name="test_env"))
440442
evaluator.cleanup(
441-
[SnapshotTableCleanupTask(snapshot=snapshot.table_info, dev_table_only=dev_table_only)]
443+
[SnapshotTableCleanupTask(snapshot=snapshot.table_info, dev_table_only=dev_table_only)],
444+
on_complete=on_cleanup_mock,
442445
)
446+
assert on_cleanup_mock.call_count == 1 if dev_table_only else 2
443447
return snapshot
444448

445449
snapshot = create_and_cleanup("catalog.test_schema.test_model", True)
@@ -611,6 +615,39 @@ def create_and_cleanup_external_model(name: str, dev_table_only: bool):
611615
adapter_mock.drop_table.assert_not_called()
612616

613617

618+
def test_cleanup_symbolic_and_audit_snapshots_no_callback(
619+
mocker: MockerFixture, adapter_mock, make_snapshot
620+
):
621+
evaluator = SnapshotEvaluator(adapter_mock)
622+
on_complete_mock = mocker.Mock()
623+
624+
# Test external model
625+
external_model = ExternalModel(
626+
name="test_schema.external_model",
627+
kind=ExternalKind(),
628+
)
629+
external_snapshot = make_snapshot(external_model)
630+
external_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
631+
632+
# Test standalone audit
633+
audit = StandaloneAudit(name="test_audit", query=parse_one("SELECT NULL LIMIT 0"))
634+
audit_snapshot = make_snapshot(audit)
635+
audit_snapshot.categorize_as(SnapshotChangeCategory.NON_BREAKING)
636+
637+
evaluator.cleanup(
638+
[
639+
SnapshotTableCleanupTask(snapshot=external_snapshot.table_info, dev_table_only=False),
640+
SnapshotTableCleanupTask(snapshot=audit_snapshot.table_info, dev_table_only=False),
641+
],
642+
on_complete=on_complete_mock,
643+
)
644+
645+
# Verify that no physical tables were attempted to be dropped
646+
adapter_mock.drop_table.assert_not_called()
647+
adapter_mock.get_data_object.assert_not_called()
648+
on_complete_mock.assert_not_called()
649+
650+
614651
@pytest.mark.parametrize("view_exists", [True, False])
615652
def test_evaluate_materialized_view(
616653
mocker: MockerFixture, adapter_mock, make_snapshot, view_exists: bool

tests/integrations/jupyter/test_magics.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,6 @@ def test_destroy(
906906
"Are you ABSOLUTELY SURE you want to proceed with deletion? [y/n]:",
907907
"Environment 'prod' invalidated.",
908908
"Deleted object memory.sushi",
909-
'Deleted object "memory"."raw"."model1"',
910-
'Deleted object "memory"."raw"."model2"',
911-
'Deleted object "memory"."raw"."demographics"',
912909
"State tables removed.",
913910
"Destroy completed successfully.",
914911
]

0 commit comments

Comments
 (0)