Skip to content

fix(plan): add explainer visit method for PhysicalLayerSchemaCreationStage - #5925

Open
nkwork9999 wants to merge 1 commit into
SQLMesh:mainfrom
nkwork9999:fix/explainer-physical-layer-schema-creation-stage
Open

fix(plan): add explainer visit method for PhysicalLayerSchemaCreationStage#5925
nkwork9999 wants to merge 1 commit into
SQLMesh:mainfrom
nkwork9999:fix/explainer-physical-layer-schema-creation-stage

Conversation

@nkwork9999

Copy link
Copy Markdown
Contributor

Fixes #5619

Problem

RichExplainerConsole has no visit_physical_layer_schema_creation_stage, so when a plan contains PhysicalLayerSchemaCreationStage, explain() falls into the hasattr guard at explainer.py:134:

sqlmesh.core.plan.explainer - ERROR - Unexpected stage: PhysicalLayerSchemaCreationStage

The stage is then silently dropped from the explained plan, even though PlanEvaluator handles it in evaluator.py:209.

Change

Add the missing visit method. It mirrors the schema derivation in SnapshotEvaluator.create_physical_schemas / _create_schemas — non-symbolic models only, table name resolved through the stage's deployability index, deduplicated by (db, catalog) — and lists the distinct physical schemas that will be created. Returns None when there is nothing to create, consistent with the other Optional[Tree] visit methods.

Placed directly before visit_physical_layer_update_stage to match the stage ordering produced in stages.py.

Output on examples/sushi:

├── Create physical schemas if they do not exist
│   └── memory.sqlmesh__sushi
├── Backfill models by running their queries and run standalone audits
│   ├── sushi.waiter_revenue_by_day -> ...

Tests

test_plan_explain previously only asserted that explaining does not raise, which is why this went unnoticed. It now asserts that no stage is reported as unexpected, which covers this stage and guards against the same omission for stages added later.

Verified the test fails on main with the fix reverted:

E  AssertionError: assert 'Unexpected stage' not in '...'
E    'Unexpected stage' is contained here:
E      er.py:134 Unexpected stage: PhysicalLayerSchemaCreationStage

tests/core/test_plan.py, tests/core/test_plan_stages.py, tests/core/test_context.py and tests/core/integration/test_plan_options.py pass (207 tests), as do ruff format, ruff check and mypy on the changed files.

…Stage

`RichExplainerConsole` had no `visit_physical_layer_schema_creation_stage`,
so explaining a plan that includes `PhysicalLayerSchemaCreationStage` logged
`ERROR - Unexpected stage: PhysicalLayerSchemaCreationStage` and silently
omitted the stage from the explained plan.

Add the missing visit method. It mirrors the schema derivation in
`SnapshotEvaluator.create_physical_schemas` (non-symbolic models only, table
name resolved through the deployability index) and lists the distinct physical
schemas that will be created.

`test_plan_explain` now asserts that no stage is reported as unexpected, which
covers this stage and guards against the same omission for future ones.

Fixes SQLMesh#5619

Signed-off-by: nkwork9999 <143652584+nkwork9999@users.noreply.github.com>
@nkwork9999
nkwork9999 force-pushed the fix/explainer-physical-layer-schema-creation-stage branch from 6cffcaf to 40e26aa Compare July 28, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explainer doesn't have visit method for PhysicalLayerSchemaCreationStage

1 participant