Skip to content

Commit 5a5034c

Browse files
committed
Fix: Make sure we never use actual physical names of external tables when evaluating snapshots
1 parent 3147103 commit 5a5034c

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

sqlmesh/core/snapshot/definition.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ def _table_name(self, version: str, is_dev: bool, for_read: bool) -> str:
223223
is_dev: Whether the table name will be used in development mode.
224224
for_read: Whether the table name will be used for reading by a different snapshot.
225225
"""
226-
if self.is_external:
227-
return self.name
228-
229226
if is_dev and for_read:
230227
# If this snapshot is used for **reading**, return a temporary table
231228
# only if this snapshot captures a direct forward-only change applied to its model.

sqlmesh/core/snapshot/evaluator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ def _cleanup_snapshot(self, snapshot: SnapshotInfoLike) -> None:
470470
table_names.append(snapshot.table_name(is_dev=True))
471471

472472
for table_name in table_names:
473+
if not table_name.startswith(snapshot.physical_schema):
474+
raise SQLMeshError(
475+
f"Table '{table_name}' is not a part of the physical schema '{snapshot.physical_schema}' and so can't be dropped."
476+
)
477+
473478
if snapshot.is_materialized:
474479
self.adapter.drop_table(table_name)
475480
logger.info("Dropped table '%s'", table_name)

tests/core/test_schema_loader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def test_create_external_models(sushi_context, assert_exp_eq):
7171

7272
snapshot = sushi_context.snapshots["sushi.raw_fruits"]
7373
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
74-
assert snapshot.table_name() == "sushi.raw_fruits"
7574

7675
fruits = sushi_context.models["sushi.fruits"]
7776
assert not fruits.kind.is_symbolic

0 commit comments

Comments
 (0)