Repository navigation
fix: load materializations during cleanup #6162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,29 @@ def test_table_name(init_and_plan_context: t.Callable): | |
| ) | ||
|
|
||
|
|
||
| def test_janitor_loads_materialization(mocker: MockerFixture, tmp_path: Path): | ||
| models_dir = tmp_path / "models" | ||
| models_dir.mkdir(exist_ok=True) | ||
|
|
||
| test_model = models_dir / "model.sql" | ||
|
|
||
| with open(test_model, "w") as f: | ||
| f.write( | ||
| "MODEL(name test.model, kind CUSTOM (materialization 'custom_full')); SELECT 1 AS col" | ||
| ) | ||
|
|
||
| config = Config(model_defaults=ModelDefaultsConfig(dialect="duckdb")) | ||
| ctx = Context(paths=[tmp_path], config=config) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provide the materialization and test an unloaded context. If Create the materialization in the temporary project. Then run cleanup with a fresh
|
||
| ctx.plan("dev", no_prompts=True, auto_apply=True) | ||
|
|
||
| load_materializations_spy = mocker.spy(Context, "_load_materializations") | ||
|
|
||
| ctx.invalidate_environment("dev") | ||
| ctx.run_janitor(ignore_ttl=True) | ||
|
|
||
| load_materializations_spy.assert_called_once() | ||
|
|
||
|
|
||
| def test_janitor_cleanup_order(mocker: MockerFixture, tmp_path: Path): | ||
| def setup_scenario(): | ||
| models_dir = tmp_path / "models" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Load materializations only once per context.
For a production run with
load=False,run()calls this path and then calls_load_materializations()again at Line 906. The helper leaves_loadedfalse, and the loader re-imports each file. (raw.githubusercontent.com)A materialization that registers a Prometheus counter at module scope fails on the second import with a duplicate-timeseries error, stopping the run. (raw.githubusercontent.com) Track materialization loading separately from full project loading, or avoid the second call.