Skip to content

Commit 0da3c3a

Browse files
Fix: Make jinja_macros optional for environment statements
1 parent 9a67826 commit 0da3c3a

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

sqlmesh/core/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class EnvironmentStatements(PydanticModel):
219219
before_all: t.List[str]
220220
after_all: t.List[str]
221221
python_env: t.Dict[str, Executable]
222-
jinja_macros: JinjaMacroRegistry = JinjaMacroRegistry()
222+
jinja_macros: t.Optional[JinjaMacroRegistry] = None
223223

224224

225225
def execute_environment_statements(

sqlmesh/core/renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def render_statements(
437437
expression,
438438
dialect,
439439
[],
440-
jinja_macro_registry=jinja_macros or JinjaMacroRegistry(),
440+
jinja_macro_registry=jinja_macros or None,
441441
python_env=python_env,
442442
default_catalog=default_catalog,
443443
quote_identifiers=False,

tests/core/test_integration.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5268,3 +5268,32 @@ def add_projection_to_model(model: SqlModel, literal: bool = True) -> SqlModel:
52685268
"query": model.query.select(one_expr), # type: ignore
52695269
}
52705270
return SqlModel.parse_obj(kwargs)
5271+
5272+
5273+
def test_plan_environment_statements_doesnt_cause_extra_diff(tmp_path: Path):
5274+
model_a = """
5275+
MODEL (
5276+
name test_schema.a,
5277+
kind FULL,
5278+
);
5279+
5280+
SELECT 1;
5281+
"""
5282+
5283+
models_dir = tmp_path / "models"
5284+
models_dir.mkdir()
5285+
5286+
(models_dir / "a.sql").write_text(model_a)
5287+
5288+
config = Config(
5289+
model_defaults=ModelDefaultsConfig(dialect="duckdb"),
5290+
before_all=["select 1 as before_all"],
5291+
after_all=["select 2 as after_all"],
5292+
)
5293+
ctx = Context(paths=[tmp_path], config=config)
5294+
5295+
# first plan - should apply changes
5296+
assert ctx.plan(auto_apply=True, no_prompts=True).has_changes
5297+
5298+
# second plan - nothing has changed so should report no changes
5299+
assert not ctx.plan(auto_apply=True, no_prompts=True).has_changes

0 commit comments

Comments
 (0)