Skip to content

fix(context): reject non-dict models/views in MDL conversion#2567

Open
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/context-guard-non-dict-mdl-entries
Open

fix(context): reject non-dict models/views in MDL conversion#2567
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/context-guard-non-dict-mdl-entries

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • convert_mdl_to_project assumed every models/views entry was a dict; list litter crashed during snake_case convert.
  • Raise a clear ValueError naming the index and actual type.
  • validate_project records a ValidationError for non-dict loaded entries instead of AttributeError.

License

core/wren/** Apache-2.0.

Test plan

  • pytest tests/unit/test_convert_mdl.py -k non_dict -v (2 passed)

Real behavior proof

Non-dict model raised TypeError-ish path inside convert; now ValueError with index.

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation when importing project definitions.
    • Clear errors are now reported when model or view entries have an invalid format, including the affected item’s position.
    • Missing or empty model and view lists are handled safely.
  • Tests

    • Added coverage for invalid model and view entries during import.

convert_mdl_to_project assumed every models/views entry was a dict and
crashed in _convert_keys_to_snake / key checks. Raise a clear ValueError.
validate_project now records ValidationError for non-dict load entries.
@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The change adds dictionary-shape checks for model and view entries during MDL conversion and project validation. Invalid conversion inputs raise indexed ValueErrors, validation records indexed errors, and unit tests cover invalid model and view entries.

Changes

Project input validation

Layer / File(s) Summary
Model and view entry shape checks
core/wren/src/wren/context.py, core/wren/tests/unit/test_convert_mdl.py
MDL conversion rejects non-dictionary model and view entries with indexed errors; project validation records indexed shape errors and skips field checks for invalid entries. Unit tests cover both conversion cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: goldmedal

Poem

A rabbit checks each model’s shape,
And views that wander from their cape.
Bad entries thump, errors appear,
Tests hop in to make it clear.
The project’s paths now safely steer.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rejecting non-dict model and view entries during MDL conversion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
core/wren/tests/unit/test_convert_mdl.py (1)

388-395: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Strengthen coverage for the complete error contract.

The model test does not verify the index or actual type, and the view test does not verify the actual type. Also add tests for validate_project to confirm invalid entries produce ValidationErrors at models[i] and views[i] instead of 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_convert_mdl.py` around lines 388 - 395, Strengthen
the tests around convert_mdl_to_project so invalid model and view entries assert
the complete ValueError message, including the entry index and actual type. Add
validate_project tests covering invalid entries in both models and views,
asserting ValidationError is returned or collected at paths models[i] and
views[i] rather than raised.
🤖 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_convert_mdl.py`:
- Around line 388-395: Strengthen the tests around convert_mdl_to_project so
invalid model and view entries assert the complete ValueError message, including
the entry index and actual type. Add validate_project tests covering invalid
entries in both models and views, asserting ValidationError is returned or
collected at paths models[i] and views[i] rather than raised.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b686601a-2397-4d93-bec3-8c644d2329ae

📥 Commits

Reviewing files that changed from the base of the PR and between 507bda6 and 91e3d3c.

📒 Files selected for processing (2)
  • core/wren/src/wren/context.py
  • core/wren/tests/unit/test_convert_mdl.py

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.

1 participant