Skip to content

Commit 2d087c3

Browse files
committed
Mirror existing cron within kind
1 parent 5e56ada commit 2d087c3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

sqlmesh/core/model/definition.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,8 +2810,12 @@ def render_field_value(value: t.Any) -> t.Any:
28102810
for key, value in field_value.items():
28112811
if key in RUNTIME_RENDERED_MODEL_FIELDS:
28122812
rendered_dict[key] = parse_strings_with_macro_refs(value, dialect)
2813-
elif key == "auto_restatement_cron":
2814-
# Don't parse auto_restatement_cron="@..." kwarg (e.g. @daily) into MacroVar
2813+
elif (
2814+
# don't parse kind auto_restatement_cron="@..." kwargs (e.g. @daily) into MacroVar
2815+
key == "auto_restatement_cron"
2816+
and isinstance(value, str)
2817+
and value.lower() in CRON_SHORTCUTS
2818+
):
28152819
rendered_dict[key] = value
28162820
elif (rendered := render_field_value(value)) is not None:
28172821
rendered_dict[key] = rendered

tests/core/test_model.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,28 @@ def my_model(context):
29042904
assert not mock_logger.call_args
29052905

29062906

2907+
def test_python_model_decorator_auto_restatement_cron() -> None:
2908+
@model(
2909+
"auto_restatement_model",
2910+
cron="@daily",
2911+
kind=dict(
2912+
name=ModelKindName.INCREMENTAL_BY_TIME_RANGE,
2913+
time_column="ds",
2914+
auto_restatement_cron="@hourly",
2915+
),
2916+
columns={'"ds"': "date", '"COL"': "int"},
2917+
)
2918+
def my_model(context):
2919+
pass
2920+
2921+
python_model = model.get_registry()["auto_restatement_model"].model(
2922+
module_path=Path("."),
2923+
path=Path("."),
2924+
)
2925+
2926+
assert python_model.auto_restatement_cron == "@hourly"
2927+
2928+
29072929
def test_python_model_decorator_col_descriptions() -> None:
29082930
# `columns` and `column_descriptions` column names are different cases, but name normalization makes both lower
29092931
@model("col_descriptions", columns={"col": "int"}, column_descriptions={"COL": "a column"})

0 commit comments

Comments
 (0)