Skip to content

Commit 7dcc2ec

Browse files
committed
Fix: ensure external is not expanded
1 parent a4b85c1 commit 7dcc2ec

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

sqlmesh/core/renderer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ def _expand(node: exp.Expression) -> exp.Expression:
212212
if isinstance(node, exp.Table) and snapshots:
213213
name = exp.table_name(node)
214214
model = snapshots[name].model if name in snapshots else None
215-
if name in expand and model and not model.is_seed:
215+
if (
216+
name in expand
217+
and model
218+
and not model.is_seed
219+
and not model.kind.is_external
220+
):
216221
return model.render_query(
217222
start=start,
218223
end=end,

sqlmesh/core/snapshot/definition.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ 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+
226229
if is_dev and for_read:
227230
# If this snapshot is used for **reading**, return a temporary table
228231
# only if this snapshot captures a direct forward-only change applied to its model.

tests/core/test_schema_loader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sqlmesh.core import constants as c
88
from sqlmesh.core.dialect import parse
99
from sqlmesh.core.model import load_model
10+
from sqlmesh.core.snapshot import SnapshotChangeCategory
1011

1112

1213
@pytest.fixture(autouse=True)
@@ -68,6 +69,10 @@ def test_create_external_models(sushi_context):
6869
"name": exp.DataType.build("VARCHAR"),
6970
}
7071

72+
snapshot = sushi_context.snapshots["sushi.raw_fruits"]
73+
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
74+
assert snapshot.table_name() == "sushi.raw_fruits"
75+
7176
fruits = sushi_context.models["sushi.fruits"]
7277
assert not fruits.kind.is_symbolic
7378
assert not fruits.kind.is_external

0 commit comments

Comments
 (0)