Repository navigation
fix(context): filter non-mapping entries in _load_views_v1 - #2604
Conversation
_load_views_v1 was the only project loader that returned raw list items without filtering out non-mappings, breaking its list[dict] contract. A hand-written v1 views.yml with a bad entry (e.g. `- null`) crashed every consumer with a bare AttributeError: validate_project, build_manifest/build_json, and both v1->v2 migration steps — the apply step could even leave a project half-migrated since it unlinks old model files before reaching the crash in the views loop. Filter at the loader to match its siblings (_load_models_v1, _load_models_v2, _load_views_v2), fixing all four consumers with one change. validate_project additionally re-checks the raw views.yml entries so a malformed file is reported as a validation error instead of silently disappearing, consistent with how it already flags malformed model columns and relationships. Fixes #2597. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughSchema v1 view loading now filters non-mapping entries. Validation separately reports malformed raw entries, while manifest generation, JSON generation, and v1-to-v2 upgrades are covered against corrupted ChangesLegacy View Resilience
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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_context.py (1)
1396-1403: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAssert that every malformed entry is reported and excluded.
The fixture contains both
nulland"junk", but validation only asserts that one matching error exists. The migration tests likewise verify the validsummaryoutput without proving that no invalid view files or directories are planned or written.Proposed test strengthening
- assert any("must be a mapping" in e.message for e in hard) + mapping_errors = { + e.path for e in hard if "must be a mapping" in e.message + } + assert mapping_errors == { + "views.yml > views[0]", + "views.yml > views[1]", + } # The well-formed sibling entry is unaffected. assert not any("summary" in e.message for e in errors)Also assert that migration creates only
views/summary/metadata.ymland that the applied project contains nojunkview directory.Also applies to: 1420-1433
🤖 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_context.py` around lines 1396 - 1403, The validation test test_validate_project_reports_v1_views_yml_non_mapping_entries must assert both malformed entries, null and "junk", produce errors while the valid summary entry remains unaffected. Strengthen the related migration tests around the applied project to verify only views/summary/metadata.yml is created and no junk view file or directory is planned or written.
🤖 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/context.py`:
- Around line 602-603: Update _load_views_v1 in core/wren/src/wren/context.py at
lines 602-603 to normalize views to an empty list unless it is a list, then
filter entries so the method always returns list[dict]. In the views validation
flow at lines 1104-1110, validate that views is a list before calling enumerate
and emit a container-level validation error for null or scalar values.
---
Nitpick comments:
In `@core/wren/tests/unit/test_context.py`:
- Around line 1396-1403: The validation test
test_validate_project_reports_v1_views_yml_non_mapping_entries must assert both
malformed entries, null and "junk", produce errors while the valid summary entry
remains unaffected. Strengthen the related migration tests around the applied
project to verify only views/summary/metadata.yml is created and no junk view
file or directory is planned or written.
🪄 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: a34879ee-678d-4e7f-94c9-cde5c08abbde
📒 Files selected for processing (2)
core/wren/src/wren/context.pycore/wren/tests/unit/test_context.py
A bare `views:` parses to None, so filtering the list without checking the container first raised TypeError — and an empty key is a far more likely hand-edit than a null list entry. Both the loader and the new validation block now check the container. `views:` (None) means "no views", same as a missing key, so it is not an error; a scalar or mapping there is, and is reported once at the container level rather than once per character. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Pushed Non-list One correction to the suggestion, though: it proposed reporting a container-level error for "null or scalar values". Reporting on
Test strengthening — done. Two new tests cover the container shapes: Unit suite: 1030 passed, 2 skipped. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
core/wren/tests/unit/test_context.py (2)
1413-1432: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExpand malformed-container regression coverage.
This covers
Noneand scalar containers, but not mapping containers, and neither case is exercised throughbuild_json,plan_upgrade, orapply_upgrade. Add those cases (preferably parametrized) so the full resilience contract is protected.🤖 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_context.py` around lines 1413 - 1432, Expand the validation tests near test_validate_project_accepts_empty_v1_views_key to cover mapping-valued views containers alongside None and scalar inputs, preferably with parametrization. For each malformed container, assert validation reports the container once without per-item errors and verify build_json, plan_upgrade, and apply_upgrade degrade safely without raising.
1457-1466: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winExercise the partially applied migration path.
This test starts from a clean project, so it does not verify the stated interrupted/partially applied migration scenario. Seed the appropriate partial
views/state beforeapply_upgradeand assert the operation remains safe and leaves only the valid view output.🤖 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_context.py` around lines 1457 - 1466, Update test_apply_upgrade_v1_to_v2_does_not_crash_on_non_mapping_view to seed an interrupted, partially applied views/ directory state after plan_upgrade and before apply_upgrade, including any existing valid output expected from that partial migration. Keep the assertions that apply_upgrade remains safe, produces the valid summary metadata, removes views.yml, and leaves no junk sibling entries.
🤖 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.
Nitpick comments:
In `@core/wren/tests/unit/test_context.py`:
- Around line 1413-1432: Expand the validation tests near
test_validate_project_accepts_empty_v1_views_key to cover mapping-valued views
containers alongside None and scalar inputs, preferably with parametrization.
For each malformed container, assert validation reports the container once
without per-item errors and verify build_json, plan_upgrade, and apply_upgrade
degrade safely without raising.
- Around line 1457-1466: Update
test_apply_upgrade_v1_to_v2_does_not_crash_on_non_mapping_view to seed an
interrupted, partially applied views/ directory state after plan_upgrade and
before apply_upgrade, including any existing valid output expected from that
partial migration. Keep the assertions that apply_upgrade remains safe, produces
the valid summary metadata, removes views.yml, and leaves no junk sibling
entries.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 61fa30b5-9d3c-490a-91f1-a5fb883dd032
📒 Files selected for processing (2)
core/wren/src/wren/context.pycore/wren/tests/unit/test_context.py
🚧 Files skipped from review as they are similar to previous changes (1)
- core/wren/src/wren/context.py
…sumers Covers mapping containers alongside scalar/int, and drives build_json, plan_upgrade and apply_upgrade rather than build_manifest alone, so the "degrade to no views" contract is pinned at every consumer. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Pushed Malformed-container coverage — done. Partially-applied migration — not adding this. The half-migrated state described in #2597 is a consequence of the crash, not a precondition for it: Seeding a partial What the existing tests do assert is the property that matters here: the migration now runs to completion on a project with a malformed |
Match 9bdae39 (Canner#2604): load_relationships drops non-dict entries; validate_project re-reads raw relationships.yml and reports malformed list/entries so hand-edits do not vanish silently.
Hand-edited YAML can set columns: to a non-list or mix bare strings into the list. Mirror Canner#2604: loaders drop/normalise to list[dict]; validate_project reports must be a list, got <type>. Formatter no longer owns the guard or infers bare strings as column names.
Hand-edited YAML can set columns: to a non-list or mix bare strings into the list. Mirror Canner#2604: loaders drop/normalise to list[dict]; validate_project reports must be a list, got <type>. Formatter no longer owns the guard or infers bare strings as column names.
Hand-edited YAML can set columns: to a non-list or mix bare strings into the list. Mirror Canner#2604: loaders drop/normalise to list[dict]; validate_project reports must be a list, got <type>. Formatter no longer owns the guard or infers bare strings as column names.
Summary
Fixes #2597.
_load_views_v1was the only project loader that did not filter non-mapping entries out of the list it returns, while its return annotation promiseslist[dict]and all four of its consumers call.get()/.pop()on the entries.What failure does this repair?
A legacy (
schema_version: 1) project whose hand-writtenviews.ymlcontains a non-mapping list entry:Every consumer crashes with a bare
AttributeError:validate_project'NoneType' object has no attribute 'get'build_manifest/build_json'NoneType' object has no attribute 'pop'(the_source_dirstrip)_plan_v1_to_v2'NoneType' object has no attribute 'get'_apply_v1_to_v2models/<name>/directories andunlink()ed the old flat filesThe last one is the worst: the migration leaves the project half-converted — models restructured,
views.ymluntouched, noviews/directory — and reports it as an unhandledAttributeError. The first is the most incongruous:validate_projectexists to tell users what is wrong with a hand-edited project, and instead it crashes on one.The sibling loaders
_load_models_v1,_load_models_v2and_load_views_v2all guard their items already; this one did not.The fix
One filter at the loader, covering all four consumers:
validate_projectadditionally reports the bad entries rather than letting them vanish. The issue raised drop-vs-report as an open question; reporting is what the surrounding code already does — both the model-columns loop and the relationships loopisinstance-check each item and append aValidationErrorinstead of relying on silent filtering. Swallowing a hand-edit mistake would be inconsistent with the function's own conventions and its purpose. The addition is gated behindsv == 1and an existence check, so it is a no-op for v2+ projects and adds no errors for well-formed v1 ones. Build and migration keep the loader's silent-drop behaviour, matching their siblings.How is it tested?
Five regression tests in
tests/unit/test_context.py, each driving a real consumer on atmp_pathv1 fixture rather than testing the loader helper in isolation —validate_project,build_manifest,build_json,_plan_v1_to_v2,_apply_v1_to_v2. They live undertests/unit/so the defaultunit testsjob executes them; files undertests/connectors/are gated behind optional extras or containers and would not run.pytest tests/unit/ --ignore=tests/unit/test_memory.py --ignore=tests/unit/test_mcp_server.py→ 1028 passed, 2 skipped.ruff format --check src/andruff check src/clean.Duplicate check
No open PR touches
_load_views_v1or the v1 loaders. #2567 patchesvalidate_projectfor a related non-dict concern but at the consumer rather than the loader, and does not coverbuild_manifestor either migration path.Noted, deliberately not fixed here
context.validate_manifesthas the same shape — it decodes a base64 manifest and iteratesmanifest.get("views", [])with.get()calls beforeWrenEngineis constructed, and construction does not deserialize. It is not reachable with malformed input today: its only caller rebuilds the manifest throughbuild_json(), so it always receives loader-sanitized data and never a hand-editedtarget/mdl.json. Left alone to keep this change scoped.🤖 Generated with Claude Code
Summary by CodeRabbit
views.yml), including clear errors whenviewsisn’t a list and when list entries aren’t valid mappings.views.ymlscenarios and v1→v2 upgrade resilience.