Skip to content

Commit

Permalink
Fix: ensure strict defaults dont break all the models to which they a… (
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma authored Jan 17, 2025
1 parent ef9cb47 commit 17a2e4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sqlmesh/core/model/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,9 @@ def _create_model(
kwargs["kind"] = create_model_kind(raw_kind, dialect, defaults or {})

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

statements = []

Expand Down
11 changes: 11 additions & 0 deletions tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7054,6 +7054,17 @@ def test_compile_time_checks(tmp_path: Path, assert_exp_eq):
context.upsert_model(model)
context.plan(auto_apply=True, no_prompts=True)

# Ensure strict defaults don't break all non SQL models to which they weren't applicable in the first place
seed_strict_defaults = create_seed_model(
"test_db.test_seed_model", model_kind, defaults=strict_default
)
external_strict_defaults = create_external_model(
"test_db.test_external_model", columns={"a": "int", "limit": "int"}, defaults=strict_default
)
context.upsert_model(seed_strict_defaults)
context.upsert_model(external_strict_defaults)
context.plan(auto_apply=True, no_prompts=True)


def test_partition_interval_unit():
expressions = d.parse(
Expand Down

0 comments on commit 17a2e4f

Please sign in to comment.