fix(memory): reject non-list relationship models in schema_indexer - #2605
Conversation
|
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)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughRelationship endpoint handling now validates that ChangesRelationship model validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
core/wren/tests/unit/test_schema_indexer_rel_models_non_list.py (1)
47-60: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winExercise valid-list extraction as well as description.
This test verifies only
describe_schema; it does not protect_relationship_record’s valid-list behavior. Assert thatextract_schema_itemsemits the relationship with the expectedmodel_nameand text.🤖 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_schema_indexer_rel_models_non_list.py` around lines 47 - 60, Extend test_valid_list_models_unchanged to call extract_schema_items with the same valid relationship fixture, then assert the emitted relationship record has model_name set to the expected model and contains the expected relationship text, while retaining the existing describe_schema assertion.
🤖 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/tests/unit/test_schema_indexer_rel_models_non_list.py`:
- Around line 40-44: Extend test_missing_models_still_ok to use a relationship
with models explicitly set to None, and assert that both describe_schema and
extract_schema_items continue to include the relationship name as with an
omitted models key.
- Around line 10-19: Strengthen both tests,
test_describe_schema_non_list_relationship_models_raises and
test_extract_schema_items_non_list_relationship_models_raises, to assert the
complete ValueError message: it must identify relationship “r” and state that
models must be a list, rather than matching only “models”.
---
Outside diff comments:
In `@core/wren/tests/unit/test_schema_indexer_rel_models_non_list.py`:
- Around line 47-60: Extend test_valid_list_models_unchanged to call
extract_schema_items with the same valid relationship fixture, then assert the
emitted relationship record has model_name set to the expected model and
contains the expected relationship text, while retaining the existing
describe_schema assertion.
🪄 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: 24128706-bba9-4233-a221-77a9a62b39bb
📒 Files selected for processing (2)
core/wren/src/wren/memory/schema_indexer.pycore/wren/tests/unit/test_schema_indexer_rel_models_non_list.py
Converge policy with Canner#2605 per review: a truthy non-list nested field (columns/measures/dimensions/timeDimensions) is a structural manifest error and now raises ValueError instead of silently emptying the index. None/missing/empty still pass through as []. The CLI already catches ValueError -> 'Malformed manifest'. Thread a field name for a clear message; update tests to assert raise + the passthrough case.
Address review: _as_list short-circuited on any falsy value, so
columns: {} / 0 / "" silently indexed zero columns — the exact
outcome the docstring says it raises to prevent. Change to only pass
None; every other non-list raises, matching _iter_section and Canner#2605's
_relationship_models (one rule across the module). Unify message to
manifest['field'] form, make field a required positional, drop brittle
len==4 assert, add falsy non-list test cases.
Address review: _as_list short-circuited on any falsy value, so
columns: {} / 0 / "" silently indexed zero columns — the exact
outcome the docstring says it raises to prevent. Change to only pass
None; every other non-list raises, matching _iter_section and Canner#2605's
_relationship_models (one rule across the module). Unify message to
manifest['field'] form, make field a required positional, drop brittle
len==4 assert, add falsy non-list test cases.
|
Reviewed at 0ab3957. This one is right, and it's the one of this batch I'd merge first. The bug is real and the fix matches the reproduction. #2590 pins it on The sweep is complete for this file. The policy is the strict one, and it was right the first time. Only Tests go through the real entry points. On the error-message format — I want to correct the direction I gave on #2586. There I asked that PR to match It names the offending entity, which is what someone fixing their So the convergence should go toward your form, not away from it: top-level stays Two small things, neither blocking:
One behavioural note that applies to this and #2586 equally: the new Ready to merge as far as I'm concerned, and it should go in ahead of #2586 so that PR's "one rule across the module" docstring is true when it lands. |
|
Thanks for the thorough read, @goldmedal — and for confirming the strict- Addressed both nits in
On the error-message convergence: glad the |
|
Two small test additions before I approve — both are CodeRabbit's open comments, and I agree with both. 1. Assert the whole error contract, not just with pytest.raises(ValueError, match=r"relationship 'r': 'models' must be a list, got dict"):Worth parametrizing the expected type name alongside 2. Cover explicit relationships:
- name: r1
models:parses to text = describe_schema({"relationships": [{"name": "r1", "models": None}]})
assert "r1" in textNeither changes the production code — it's already correct. Push those and I'll approve and merge; that also closes #2590. Heads-up on ordering: this is going in ahead of #2586, so that one will need a rebase, plus the message-format change I noted over there (nested fields naming the parent entity, following the form you used here). |
|
Done in
No production changes. Thanks — and noted on the #2586 rebase + nested-field message form following this one. |
|
Re-reviewed at 8345a5b. Both asks are done properly, and you took the optional nit too:
CI is green on all ten checks and the branch is One last thing, and it's my miss for not catching it in the previous two passes — the helper's docstring references a function that doesn't exist: (same policy as :func:`_require_list_section` for top-level sections).There is no One word: (same policy as :func:`_iter_section` for top-level sections).Push that and I'll approve and merge — or if you'd rather not spend a round on a docstring, say so and I'll merge as-is and you can correct it in the #2586 rebase, since that PR is already touching the neighbouring docstring. Either is fine by me; the code itself is done. |
|
Fixed in |
Converge policy with Canner#2605 per review: a truthy non-list nested field (columns/measures/dimensions/timeDimensions) is a structural manifest error and now raises ValueError instead of silently emptying the index. None/missing/empty still pass through as []. The CLI already catches ValueError -> 'Malformed manifest'. Thread a field name for a clear message; update tests to assert raise + the passthrough case.
Address review: _as_list short-circuited on any falsy value, so
columns: {} / 0 / "" silently indexed zero columns — the exact
outcome the docstring says it raises to prevent. Change to only pass
None; every other non-list raises, matching _iter_section and Canner#2605's
_relationship_models (one rule across the module). Unify message to
manifest['field'] form, make field a required positional, drop brittle
len==4 assert, add falsy non-list test cases.
Update _as_list to surface the parent entity in the raised ValueError instead of the top-level 'manifest["columns"]' format, aligning with the new Canner#2605 relationship implementation. Also replaces earlier tests with exact message assertions. Requested-by: goldmedal (Canner#2586)
Summary
Reject non-list
relationship.modelsinschema_indexerwithValueErrorinstead of KeyError/TypeError or silently truncating string endpoints into single-character join sides.Motivation
Closes #2590. Applies the #2533 malformed-manifest list policy to relationship
modelsat both read sites. (Other inner fields —columns,measures,dimensions,timeDimensions— are handled separately in #2586.)Real behavior proof
Before:
models: "orders"renderedo → rand indexedmodel_name: 'o'. After:ValueErrornaming the relationship.Test plan
Summary by CodeRabbit
models, it must be a list; otherwise schema description and extraction now fail fast with aValueError.modelsandmodels: nullas empty, while keeping valid list-based relationship indexing behavior unchanged.modelsinputs, regression coverage for truncated endpoint output, and verification that missing/null/valid list cases behave as expected.