Skip to content

fix(core-py): drop orphan cubes when their base model is pruned#2362

Open
goldmedal wants to merge 1 commit into
mainfrom
fix/drop-orphan-cubes-on-prune
Open

fix(core-py): drop orphan cubes when their base model is pruned#2362
goldmedal wants to merge 1 commit into
mainfrom
fix/drop-orphan-cubes-on-prune

Conversation

@goldmedal

@goldmedal goldmedal commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Problem — fixes #2360

With a cube defined in the manifest, querying any table other than the cube's base model fails:

[INVALID_SQL] Failed to analyze MDL: Error during planning:
Cube 'xxxx': baseObject 'xxxxx' is not a defined Model or View phase=SQL_PLANNING

Root cause

ManifestExtractor (extractor.rs) prunes models down to those a query reaches, but kept all cubes unconditionally (cubes: mdl.manifest.cubes.clone()). When a query touches only tables unrelated to a cube's baseObject, that base model gets pruned away while the cube is retained — leaving an orphan cube whose baseObject no longer resolves. wren-core's lineage validation (lineage.rs) then rejects the extracted manifest.

The full-manifest fallback in engine._plan() does not rescue this: extraction itself succeeds (the orphan is silent), and the failure surfaces later in get_session_context, where there is no fallback — so the query hard-fails. Even a scalar SELECT 1 breaks once a cube exists.

Fix

Filter cubes to those whose baseObject still resolves to a kept model or view (extract_cubes). A cube query emits SELECT ... FROM <baseObject>, so a queried cube's base is always pulled into the extracted manifest — dropping orphans is safe and never removes a cube the query actually needs.

Verification

  • Rustcargo test --no-default-features extractor: 36 passed, incl. 6 new test_extract_manifest_for_cubes cases (model-based, view-based, scalar/no-model, unrelated-model).
  • End-to-end repro — manifest with a revenue cube over orders + a separate parts model; extract_by(["parts"]) then SessionContext.transform_sql("SELECT ... FROM parts"):
    • before: extracted cubes ['revenue'] (orphan) → baseObject 'orders' is not a defined Model or View
    • after: extracted cubes [] → transform succeeds
  • No regressionpytest tests/unit/test_cube_cli.py: 16 passed (querying the cube itself still pulls in its base and works).
  • cargo fmt --check clean, cargo clippy --no-default-features --all-targets no warnings.

Scope

One file: core/wren-core-py/src/extractor.rs (production change + Rust regression tests). No public API change; Manifest.cubes is unchanged in shape.

🤖 Generated with Claude Code

Manifest extraction prunes models down to those a query reaches, but kept
all cubes unconditionally. A cube whose baseObject model got pruned then
failed wren-core MDL analysis with "baseObject is not a defined Model or
View" — so any query touching only tables unrelated to a cube's base, or a
scalar query referencing no model, broke once a cube existed (issue #2360).

Filter cubes to those whose baseObject still resolves to a kept model or
view. Cube queries emit `SELECT ... FROM <baseObject>`, so a queried cube's
base model is always pulled in — dropping orphans is therefore safe.

Backport of Canner/wren-engine-saas #892 (+ #895 view-cube coverage).

Closes #2360

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added python Pull requests that update Python code core labels Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Manifest extraction now prunes cubes whose baseObject targets are not in the extracted models and views. A new extract_cubes helper filters the manifest cubes, and tests validate retention and pruning across multiple query scenarios.

Changes

Manifest cube pruning

Layer / File(s) Summary
Cube filtering implementation
core/wren-core-py/src/extractor.rs
Cube type imported; new extract_cubes helper filters cubes by checking baseObject membership in extracted models/views; manifest construction uses the filtered used_cubes set instead of cloning all input cubes.
Cube pruning test fixture and validation
core/wren-core-py/src/extractor.rs
CubeBuilder added to test imports; test fixture defines cube instances based on models and views; test_extract_manifest_for_cubes validates retention and pruning across direct model queries, relationship-derived models, scalar queries, unrelated models, and view-based scoping scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

rust, core, python

Poem

🐰 A cube once lost, now finds its way,
Pruning orphans from manifest's display,
baseObjects checked with care so true,
Models and views keep cubes in view,
SQL errors fade—the query runs anew! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: filtering orphan cubes during manifest extraction when their base model is pruned.
Linked Issues check ✅ Passed The PR implementation directly addresses issue #2360 by filtering cubes to only those whose baseObject resolves to retained models/views, preventing orphan cubes from breaking unrelated queries.
Out of Scope Changes check ✅ Passed All changes are confined to the manifest extraction logic in extractor.rs and directly support the objective of filtering orphan cubes; no unrelated modifications present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/drop-orphan-cubes-on-prune

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@goldmedal goldmedal requested a review from douenergy June 12, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: [INVALID_SQL] Failed to analyze MDL: Error during planning: Cube 'xxxx': baseObject 'xxxxx' is not a defined Model or View phase=SQL_PLANNING

1 participant