Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlmesh/core/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class EnvironmentStatements(PydanticModel):
before_all: t.List[str]
after_all: t.List[str]
python_env: t.Dict[str, Executable]
jinja_macros: JinjaMacroRegistry = JinjaMacroRegistry()
jinja_macros: t.Optional[JinjaMacroRegistry] = None


def execute_environment_statements(
Expand Down
2 changes: 1 addition & 1 deletion sqlmesh/core/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def render_statements(
expression,
dialect,
[],
jinja_macro_registry=jinja_macros or JinjaMacroRegistry(),
jinja_macro_registry=jinja_macros,
python_env=python_env,
default_catalog=default_catalog,
quote_identifiers=False,
Expand Down
29 changes: 29 additions & 0 deletions tests/core/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5268,3 +5268,32 @@ def add_projection_to_model(model: SqlModel, literal: bool = True) -> SqlModel:
"query": model.query.select(one_expr), # type: ignore
}
return SqlModel.parse_obj(kwargs)


def test_plan_environment_statements_doesnt_cause_extra_diff(tmp_path: Path):
model_a = """
MODEL (
name test_schema.a,
kind FULL,
);

SELECT 1;
"""

models_dir = tmp_path / "models"
models_dir.mkdir()

(models_dir / "a.sql").write_text(model_a)

config = Config(
model_defaults=ModelDefaultsConfig(dialect="duckdb"),
before_all=["select 1 as before_all"],
after_all=["select 2 as after_all"],
)
ctx = Context(paths=[tmp_path], config=config)

# first plan - should apply changes
assert ctx.plan(auto_apply=True, no_prompts=True).has_changes

# second plan - nothing has changed so should report no changes
assert not ctx.plan(auto_apply=True, no_prompts=True).has_changes