fix(mdl): skip non-dict models/columns/views in CTERewriter - #2572
fix(mdl): skip non-dict models/columns/views in CTERewriter#2572Bartok9 wants to merge 1 commit into
Conversation
Closes nothing filed; defensive MDL parse so one corrupt catalog row cannot TypeError CTE rewrite during planning.
WalkthroughChangesCTE manifest validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
core/wren/tests/unit/test_cte_rewriter_nonduct.py (1)
26-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for nameless models in the collision scan.
This test covers malformed entries but does not include a dict model without a valid
namecontaining case-distinct visible columns. Add that case using a case-insensitive dialect and assert construction skips the malformed model without raising.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@core/wren/tests/unit/test_cte_rewriter_nonduct.py` around lines 26 - 54, Extend test_skips_nonduct_models_and_views with a dict model whose name is missing or invalid and whose visible columns differ only by case. Construct the rewriter using a case-insensitive dialect, then assert malformed-model construction completes without raising and the nameless model is excluded from the indexed model data.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@core/wren/src/wren/mdl/cte_rewriter.py`:
- Around line 224-226: Update both case-collision scans in the relevant rewriter
logic to skip model dictionaries unless their name is a non-empty string,
matching the initialization filter. Store the validated name locally and use it
when calling or formatting _raise_case_collision, avoiding direct model['name']
access for discarded models.
---
Nitpick comments:
In `@core/wren/tests/unit/test_cte_rewriter_nonduct.py`:
- Around line 26-54: Extend test_skips_nonduct_models_and_views with a dict
model whose name is missing or invalid and whose visible columns differ only by
case. Construct the rewriter using a case-insensitive dialect, then assert
malformed-model construction completes without raising and the nameless model is
excluded from the indexed model data.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 36945b78-99b9-4134-8534-d9b31017d180
📒 Files selected for processing (2)
core/wren/src/wren/mdl/cte_rewriter.pycore/wren/tests/unit/test_cte_rewriter_nonduct.py
| for model in self.manifest.get("models", []): | ||
| if not isinstance(model, dict): | ||
| continue |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Apply the valid-name filter to collision scans.
Initialization skips models whose name is missing, empty, or non-string, but the case-collision scans still process those dicts. A discarded model containing visible Year/year columns can therefore activate case-sensitive mode, or reach _raise_case_collision() and fail at model['name'] with KeyError.
Use the same name predicate in both scans and interpolate the validated local name in the error message.
Proposed fix
for model in self.manifest.get("models", []):
if not isinstance(model, dict):
continue
+ model_name = model.get("name")
+ if not isinstance(model_name, str) or not model_name:
+ continue- f"Model '{model['name']}' has columns that differ "
+ f"Model '{model_name}' has columns that differ "Also applies to: 242-244
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@core/wren/src/wren/mdl/cte_rewriter.py` around lines 224 - 226, Update both
case-collision scans in the relevant rewriter logic to skip model dictionaries
unless their name is a non-empty string, matching the initialization filter.
Store the validated name locally and use it when calling or formatting
_raise_case_collision, avoiding direct model['name'] access for discarded
models.
|
Passing on this one too, for the same reason as #2546 — but the argument is actually stronger here.
On top of that, in the normal path So the guards can't fire, and the tests only exercise the guarded functions directly rather than any reachable path. I'd rather keep the invariant explicit — manifest schema is validated once, in |
|
Agreed — with |
Summary
_iter_model_column_namesand case-collision scans the same wayLicense
Apache-2.0 (
core/**).Motivation
A single non-object row in
manifest.models/columns/viewsraisedTypeError/KeyErrorduring rewriter construction and blocked planning for the whole catalog. Match defensive guards already used in memory/mcp formatters.Verification
— 2 passed
Duplicate check
Summary by CodeRabbit
Bug Fixes
Tests