Skip to content

Commit 644e06b

Browse files
simen-strandclaude
andcommitted
Chore: add docstrings for external model default statements
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Simen Strand <simen.strand@netcheck.de>
1 parent 0fe0645 commit 644e06b

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎sqlmesh/core/model/definition.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,12 @@ def _create_model(
25832583
use_original_sql: bool = False,
25842584
**kwargs: t.Any,
25852585
) -> Model:
2586+
"""Creates a model of the given class, applying the project's model defaults.
2587+
2588+
Defaults that don't apply to the model class are dropped. External models, for example, don't
2589+
inherit the default gateway or the default pre-statements, post-statements and on-virtual-update
2590+
statements.
2591+
"""
25862592
validate_extra_and_required_fields(
25872593
klass,
25882594
{"name", *kwargs} - {"grain", "table_properties"},

‎tests/core/test_context.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,6 +4431,11 @@ def test_model_defaults_statements_with_on_virtual_update(tmp_path: Path):
44314431
def test_model_defaults_statements_not_applied_to_external_models(
44324432
tmp_path: Path, statement_type: str
44334433
):
4434+
"""Changing a default statement that calls a project macro doesn't break the plan.
4435+
4436+
External models used to inherit the statement without the project's macros, so the second
4437+
plan failed when it rendered their copy to compare it.
4438+
"""
44344439
(tmp_path / "macros").mkdir()
44354440
(tmp_path / "macros" / "tag.py").write_text(
44364441
"""

‎tests/core/test_model.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13553,6 +13553,7 @@ def test_external_model_does_not_inherit_model_defaults_gateway() -> None:
1355313553

1355413554

1355513555
def test_external_model_does_not_inherit_model_defaults_statements() -> None:
13556+
"""External models drop the default statements but keep explicit ones; SQL models inherit them."""
1355613557
defaults = ModelDefaultsConfig(
1355713558
dialect="duckdb",
1355813559
pre_statements=["SET a = 1"],

0 commit comments

Comments
 (0)