-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(memory): skip non-dict columns in schema_indexer #2515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Bartok9
wants to merge
5
commits into
Canner:main
from
Bartok9:fix/schema-indexer-skip-non-dict-columns
+113
−7
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e99347
fix(memory): skip non-dict columns in schema_indexer
Bartok9 5bd34dd
style(memory): ruff format schema_indexer non-dict guard
Bartok9 589e0bb
refactor(memory): pre-filter valid columns in schema description
Bartok9 0d07541
style: ruff format schema_indexer
Bartok9 8730311
fix(memory): widen null-slot guards, drop unreachable raise, tighten …
Bartok9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
core/wren/tests/unit/test_schema_indexer_malformed_columns.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| """schema_indexer must skip non-dict / nameless columns.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from wren.memory.schema_indexer import describe_schema, extract_schema_items | ||
|
|
||
|
|
||
| def test_describe_schema_skips_non_dict_columns(): | ||
| text = describe_schema( | ||
| { | ||
| "models": [ | ||
| { | ||
| "name": "orders", | ||
| "columns": [None, {"name": "amount", "type": "int"}, {"type": "x"}], | ||
| } | ||
| ] | ||
| } | ||
| ) | ||
| assert "amount" in text | ||
| # Exactly one column entry rendered (the malformed ones are dropped). | ||
| assert text.count(" - ") == 1 | ||
|
|
||
|
|
||
| def test_describe_schema_omits_dangling_columns_header(): | ||
| # When every column is malformed, no dangling " Columns:" header (589e0bb). | ||
| text = describe_schema( | ||
| {"models": [{"name": "orders", "columns": [None, {"type": "x"}]}]} | ||
| ) | ||
| assert "Columns:" not in text | ||
| assert "### Model: orders" in text | ||
|
|
||
|
|
||
| def test_describe_schema_skips_empty_string_name_and_null_columns(): | ||
| text = describe_schema( | ||
| { | ||
| "models": [ | ||
| {"name": "a", "columns": [{"name": "", "type": "int"}]}, | ||
| {"name": "b", "columns": None}, | ||
| ] | ||
| } | ||
| ) | ||
| assert "### Model: a" in text | ||
| assert "### Model: b" in text | ||
| assert " - " not in text | ||
|
|
||
|
|
||
| def test_describe_schema_skips_null_model_relationship_view_slots(): | ||
| # Null slots in hand-edited manifests must not crash. | ||
| text = describe_schema({"models": [None], "relationships": [None], "views": [None]}) | ||
| assert isinstance(text, str) | ||
|
|
||
|
|
||
| def test_extract_schema_items_skips_null_model_slots(): | ||
| items = extract_schema_items({"models": [None, {"columns": []}]}) | ||
| assert items == [] | ||
|
|
||
|
|
||
| def test_extract_schema_items_skips_scalar_and_empty_name_columns(): | ||
| items = extract_schema_items( | ||
| { | ||
| "models": [ | ||
| { | ||
| "name": "orders", | ||
| "columns": ["amount", {"name": "", "type": "int"}], | ||
| } | ||
| ] | ||
| } | ||
| ) | ||
| col_items = [i for i in items if i["item_type"] == "column"] | ||
| assert col_items == [] | ||
|
|
||
|
|
||
| def test_extract_schema_items_skips_non_dict_columns(): | ||
| items = extract_schema_items( | ||
| { | ||
| "models": [ | ||
| { | ||
| "name": "orders", | ||
| "columns": [None, {"name": "amount", "type": "int"}, {"type": "x"}], | ||
| } | ||
| ] | ||
| } | ||
| ) | ||
| col_items = [i for i in items if i["item_type"] == "column"] | ||
| assert len(col_items) == 1 | ||
| assert col_items[0]["item_name"] == "amount" | ||
| model_items = [i for i in items if i["item_type"] == "model"] | ||
| assert "amount" in model_items[0]["text"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Skip nameless relationships and views in both paths.
These guards reject non-dictionaries but still pass
{}or{"name": ""}to the relationship/view helpers and record builders, contrary to the PR’s stated contract. Require a truthynamehere, and add regression cases for nameless relationships/views.Proposed fix
for rel in manifest.get("relationships", []): - if isinstance(rel, dict): + if isinstance(rel, dict) and rel.get("name"): _describe_relationship(rel, lines) for rel in manifest.get("relationships", []): - if not isinstance(rel, dict): + if not isinstance(rel, dict) or not rel.get("name"): continue for view in manifest.get("views", []): - if not isinstance(view, dict): + if not isinstance(view, dict) or not view.get("name"): continueAlso applies to: 247-255
🤖 Prompt for AI Agents