Skip to content

Commit 3155d38

Browse files
committed
fix: load materializations during cleanup
Signed-off-by: lafirm <136463254+lafirm@users.noreply.github.com>
1 parent c4dbac4 commit 3155d38

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎sqlmesh/core/context.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,8 @@ def _run_janitor(
31823182
current_ts = now_timestamp()
31833183
failures: t.List[str] = []
31843184

3185+
self._load_materializations()
3186+
31853187
# Clean up expired environments by removing their views and schemas
31863188
failures.extend(
31873189
self._cleanup_environments(

‎tests/core/integration/test_aux_commands.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ def test_table_name(init_and_plan_context: t.Callable):
8686
)
8787

8888

89+
def test_janitor_loads_materialization(mocker: MockerFixture, tmp_path: Path):
90+
models_dir = tmp_path / "models"
91+
models_dir.mkdir(exist_ok=True)
92+
93+
test_model = models_dir / "model.sql"
94+
95+
with open(test_model, "w") as f:
96+
f.write(
97+
"MODEL(name test.model, kind CUSTOM (materialization 'custom_full')); SELECT 1 AS col"
98+
)
99+
100+
config = Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))
101+
ctx = Context(paths=[tmp_path], config=config)
102+
ctx.plan("dev", no_prompts=True, auto_apply=True)
103+
104+
load_materializations_spy = mocker.spy(Context, "_load_materializations")
105+
106+
ctx.invalidate_environment("dev")
107+
ctx.run_janitor(ignore_ttl=True)
108+
109+
load_materializations_spy.assert_called_once()
110+
111+
89112
def test_janitor_cleanup_order(mocker: MockerFixture, tmp_path: Path):
90113
def setup_scenario():
91114
models_dir = tmp_path / "models"

0 commit comments

Comments
 (0)