Skip to content

fix(context): filter non-dict items in load_relationships - #2613

Open
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/load-relationships-dict-items
Open

fix(context): filter non-dict items in load_relationships#2613
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/load-relationships-dict-items

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

load_relationships now returns only mapping items so its list[dict] contract matches loaders that already filter (e.g. models/views).

Motivation

Maintainer note on closed #2547: the leak is in the loader (context.py), not MCP consumers. #2608 covers describe_model container-type; this is the missing item filter.

Test plan

  • test_load_relationships_skips_non_dict_items
  • test_load_relationships_non_list_relationships_key

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of relationship configuration files with invalid or unexpected formats.
    • Invalid entries are now ignored, preventing malformed data from affecting subsequent processing.
  • Tests

    • Added coverage for non-list relationship data and lists containing invalid entries.

Loader annotates list[dict] but only checked the outer YAML object.
Consumers (validate_project, build_manifest, MCP) should not re-filter.
@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9f4d0a6d-fe6c-442a-96c7-d129544447cc

📥 Commits

Reviewing files that changed from the base of the PR and between 99f1dbd and 0245eba.

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

Walkthrough

load_relationships() now validates the YAML structure and returns only dictionary relationship entries. Unit tests cover non-dictionary list items and non-list relationships values.

Changes

Relationship YAML validation

Layer / File(s) Summary
Validate and test relationship loading
core/wren/src/wren/context.py, core/wren/tests/unit/test_context.py
load_relationships() validates the YAML root and relationships field, filters non-dictionary entries, and tests malformed inputs.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • Canner/WrenAI#2608: Adds related guards for malformed relationship entries in describe_model.

Suggested reviewers: goldmedal

Poem

I nibbled the YAML, both tidy and bright,
And skipped little scalars that weren’t quite right.
Dicts hop through the loader in a neat little stream,
While bad shapes depart like a rabbit’s daydream.
🐇 Tests now keep relationships clean!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the primary change in load_relationships.
Description check ✅ Passed The description includes summary, motivation, and test plan, which covers the core template requirements.
Linked Issues check ✅ Passed The change filters non-dict relationship entries in the loader, matching the relevant objective in #2547.
Out of Scope Changes check ✅ Passed The patch stays within the stated loader fix and its tests, with no unrelated behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

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