Skip to content

Commit 9f0e66c

Browse files
committed
Fix: create_external_models refetch existing external models closes #1132
1 parent eda2a76 commit 9f0e66c

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

sqlmesh/core/schema_loader.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ def create_schema_file(
3333
dialect: The dialect to serialize the schema as.
3434
max_workers: The max concurrent workers to fetch columns.
3535
"""
36-
external_tables = {
37-
dep for model in models.values() for dep in model.depends_on if dep not in models
38-
}
36+
external_tables = set()
37+
38+
for model in models.values():
39+
if model.kind.is_external:
40+
external_tables.add(model.name)
41+
for dep in model.depends_on:
42+
if dep not in models:
43+
external_tables.add(dep)
3944

4045
# Make sure we don't convert internal models into external ones.
4146
existing_models = state_reader.models_exist(external_tables, exclude_external=True)

tests/core/test_schema_loader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def test_create_external_models(tmpdir, assert_exp_eq):
9090
FROM "sushi"."raw_fruits" AS "raw_fruits"
9191
""",
9292
)
93+
# rerunning create external models should refetch existing external models
94+
context.create_external_models()
95+
context.load()
96+
assert context.models["sushi.raw_fruits"]
9397

9498

9599
def test_no_internal_model_conversion(tmp_path: Path, mocker: MockerFixture):

0 commit comments

Comments
 (0)