fix(context): treat non-list relationship models as validation error - #2607
fix(context): treat non-list relationship models as validation error#2607Bartok9 wants to merge 1 commit into
Conversation
Walkthrough
ChangesRelationship model 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
🤖 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 1161-1171: Update the relationship-model validation loop in the
context validation logic to verify each entry is a string before checking
membership in all_entity_names. For non-string entries, append a ValidationError
using the indexed models path (including the relationship name and entry index),
then continue validating subsequent entries without performing set membership on
the invalid value.
🪄 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: 1fd0b408-fc9c-4773-81bc-4b366fab0723
📒 Files selected for processing (2)
core/wren/src/wren/context.pycore/wren/tests/unit/test_context.py
| if not isinstance(ref_models, list): | ||
| errors.append( | ||
| ValidationError( | ||
| "error", | ||
| f"relationships > {rel_name}", | ||
| f"'models' must be a list, got {type(ref_models).__name__}", | ||
| ) | ||
| ) | ||
| ref_models = [] | ||
| for m in ref_models: | ||
| if m not in all_entity_names: |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
Validate each relationship model entry before set membership.
A value such as models: [{}] passes the list check, then m not in all_entity_names raises TypeError: unhashable type: 'dict' instead of returning validation errors. Reject non-string entries with an indexed path and continue validation.
Proposed fix
- for m in ref_models:
+ for j, m in enumerate(ref_models):
+ if not isinstance(m, str):
+ errors.append(
+ ValidationError(
+ "error",
+ f"relationships > {rel_name} > models[{j}]",
+ "'models' entries must be strings",
+ )
+ )
+ continue
if m not in all_entity_names:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if not isinstance(ref_models, list): | |
| errors.append( | |
| ValidationError( | |
| "error", | |
| f"relationships > {rel_name}", | |
| f"'models' must be a list, got {type(ref_models).__name__}", | |
| ) | |
| ) | |
| ref_models = [] | |
| for m in ref_models: | |
| if m not in all_entity_names: | |
| if not isinstance(ref_models, list): | |
| errors.append( | |
| ValidationError( | |
| "error", | |
| f"relationships > {rel_name}", | |
| f"'models' must be a list, got {type(ref_models).__name__}", | |
| ) | |
| ) | |
| ref_models = [] | |
| for j, m in enumerate(ref_models): | |
| if not isinstance(m, str): | |
| errors.append( | |
| ValidationError( | |
| "error", | |
| f"relationships > {rel_name} > models[{j}]", | |
| "'models' entries must be strings", | |
| ) | |
| ) | |
| continue | |
| if m not in all_entity_names: |
🤖 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/context.py` around lines 1161 - 1171, Update the
relationship-model validation loop in the context validation logic to verify
each entry is a string before checking membership in all_entity_names. For
non-string entries, append a ValidationError using the indexed models path
(including the relationship name and entry index), then continue validating
subsequent entries without performing set membership on the invalid value.
Summary
validate_projectreports a hard error when a relationship'smodelsis not a list, instead of iterating a string as character endpoint names.Motivation
Related to #2590. Manifest validation should surface structural type errors.
Real behavior proof
Test plan
models→ must-be-list errorSummary by CodeRabbit