Skip to content

Commit 17a2e4f

Browse files
authored
Fix: ensure strict defaults dont break all the models to which they a… (#3643)
1 parent ef9cb47 commit 17a2e4f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sqlmesh/core/model/definition.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,9 @@ def _create_model(
20872087
kwargs["kind"] = create_model_kind(raw_kind, dialect, defaults or {})
20882088

20892089
defaults = {k: v for k, v in (defaults or {}).items() if k in klass.all_fields()}
2090+
if not issubclass(klass, SqlModel):
2091+
defaults.pop("optimize_query", None)
2092+
defaults.pop("validate_query", None)
20902093

20912094
statements = []
20922095

tests/core/test_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7054,6 +7054,17 @@ def test_compile_time_checks(tmp_path: Path, assert_exp_eq):
70547054
context.upsert_model(model)
70557055
context.plan(auto_apply=True, no_prompts=True)
70567056

7057+
# Ensure strict defaults don't break all non SQL models to which they weren't applicable in the first place
7058+
seed_strict_defaults = create_seed_model(
7059+
"test_db.test_seed_model", model_kind, defaults=strict_default
7060+
)
7061+
external_strict_defaults = create_external_model(
7062+
"test_db.test_external_model", columns={"a": "int", "limit": "int"}, defaults=strict_default
7063+
)
7064+
context.upsert_model(seed_strict_defaults)
7065+
context.upsert_model(external_strict_defaults)
7066+
context.plan(auto_apply=True, no_prompts=True)
7067+
70577068

70587069
def test_partition_interval_unit():
70597070
expressions = d.parse(

0 commit comments

Comments
 (0)