Skip to content

fix(memory): skip non-dict rows in describe_schema - #2540

Closed
Bartok9 wants to merge 2 commits into
Canner:mainfrom
Bartok9:fix/schema-describe-skip-nonduct
Closed

fix(memory): skip non-dict rows in describe_schema#2540
Bartok9 wants to merge 2 commits into
Canner:mainfrom
Bartok9:fix/schema-describe-skip-nonduct

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • describe_schema skips non-dict models/relationships/views and non-dict columns.
  • Mirrors defensive guards already used for cubes measures/dimensions.

License

Apache-2.0 (core/wren/...).

Verification

cd core/wren && .venv/bin/python -m pytest tests/unit/test_schema_describe_nonduct.py -q

Test plan

  • unit test mixed malformed manifest
  • CI green

Summary by CodeRabbit

  • Bug Fixes

    • Improved schema description generation by safely handling missing or malformed manifest entries for models, relationships, and views.
    • Made model column rendering conditional so only valid, named columns appear.
    • Omitted empty “Columns” sections from the output.
  • Tests

    • Added a unit test to verify schema descriptions include valid items (models/views) and skip invalid non-conforming entries.

@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 19, 2026
@coderabbitai

coderabbitai Bot commented Jul 19, 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

Run ID: 8656a39f-bb7b-46ad-91fd-03f7de5c06b0

📥 Commits

Reviewing files that changed from the base of the PR and between 768298b and 33e39f8.

📒 Files selected for processing (1)
  • core/wren/src/wren/memory/schema_indexer.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/wren/src/wren/memory/schema_indexer.py

Walkthrough

describe_schema now validates manifest collections and skips malformed entries. Model column rendering filters invalid or nameless columns. A unit test covers mixed valid and invalid schema data.

Changes

Schema description guards

Layer / File(s) Summary
Guard schema and column entries
core/wren/src/wren/memory/schema_indexer.py, core/wren/tests/unit/test_schema_describe_nonduct.py
Manifest collections and model columns are type-checked before description helpers run, and tests verify malformed entries are skipped while valid names remain described.

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

Possibly related PRs

Poem

I’m a rabbit guarding the schema gate,
Skipping odd shapes before they propagate.
Valid models hop safely through,
Nameless columns vanish from view.
Tests thump their paws: “All clear!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 summarizes the main change: making describe_schema skip non-dict rows.
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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
core/wren/src/wren/memory/schema_indexer.py (1)

99-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prevent a dangling "Columns:" header for entirely malformed columns.

If the columns list only contains malformed entries (e.g., ["bad"]), cols evaluates to true and " Columns:" is appended to the output. However, since the loop correctly skips "bad", no columns are rendered, resulting in an empty "Columns:" section.

Filtering valid columns before appending the header ensures a cleaner output.

♻️ Proposed refactor to avoid empty headers
     cols = model.get("columns", []) or []
-    if isinstance(cols, list) and cols:
-        lines.append("  Columns:")
-        for col in cols:
-            if isinstance(col, dict) and col.get("name") is not None:
-                _describe_column(col, lines)
+    if isinstance(cols, list):
+        valid_cols = [c for c in cols if isinstance(c, dict) and c.get("name") is not None]
+        if valid_cols:
+            lines.append("  Columns:")
+            for col in valid_cols:
+                _describe_column(col, lines)
🤖 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/memory/schema_indexer.py` around lines 99 - 104, Update
the column-rendering logic around _describe_column to filter cols to entries
that are dictionaries with a non-None "name" before appending the "  Columns:"
header. Only emit the header and iterate when at least one valid column remains,
while preserving the existing handling of malformed entries.
core/wren/tests/unit/test_schema_describe_nonduct.py (1)

16-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Expand test assertions to verify columns and relationships.

The test input includes a malformed column ("bad") and a valid relationship ("r1"), but there are no assertions to ensure they are handled correctly. Adding these checks will strengthen the test coverage for the new guards.

🧪 Proposed test enhancements
     assert "orders" in text
     assert "not-a-model" not in text
     assert "v1" in text
+    assert "r1" in text
+    assert "bad" not in 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_describe_nonduct.py` around lines 16 - 18,
Expand the assertions in the schema description test to verify that the
malformed column “bad” is excluded and the valid relationship “r1” is included
in the generated text. Keep the existing model and version assertions unchanged.
🤖 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/memory/schema_indexer.py`:
- Around line 55-69: Update the model, relationship, and view iteration in the
manifest description flow to call _describe_model, _describe_relationship, and
_describe_view only when each dictionary’s "name" value is not None, matching
the existing column guard and preventing nameless entries from reaching the
helpers.

---

Nitpick comments:
In `@core/wren/src/wren/memory/schema_indexer.py`:
- Around line 99-104: Update the column-rendering logic around _describe_column
to filter cols to entries that are dictionaries with a non-None "name" before
appending the "  Columns:" header. Only emit the header and iterate when at
least one valid column remains, while preserving the existing handling of
malformed entries.

In `@core/wren/tests/unit/test_schema_describe_nonduct.py`:
- Around line 16-18: Expand the assertions in the schema description test to
verify that the malformed column “bad” is excluded and the valid relationship
“r1” is included in the generated text. Keep the existing model and version
assertions unchanged.
🪄 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

Run ID: af5da57e-ff52-457d-be07-9ea68d0d7a19

📥 Commits

Reviewing files that changed from the base of the PR and between 3dac00a and 768298b.

📒 Files selected for processing (2)
  • core/wren/src/wren/memory/schema_indexer.py
  • core/wren/tests/unit/test_schema_describe_nonduct.py

Comment thread core/wren/src/wren/memory/schema_indexer.py
…hema

Add .get("name") is not None guards so a malformed manifest entry
(e.g. {}) no longer raises KeyError in _describe_model/_relationship/_view.

Addresses CodeRabbit review feedback on Canner#2540.
@goldmedal

Copy link
Copy Markdown
Collaborator

Closing in favor of #2586, which supersedes this.

#2586 covers the same describe_schema non-dict guards, plus extract_schema_items, and factors the repeated x or [] / isinstance(..., list) dance into one _as_list helper — including the pre-existing cube guards, so the file ends up with less duplication rather than more. Three open PRs against schema_indexer.py (this one, #2541, #2586) also guarantee rebase conflicts for whichever lands second.

Review effort is better spent on #2586; nothing here is lost.

@Bartok9

Bartok9 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Makes sense — #2586 consolidates these guards through one _as_list helper with a stronger test. Closing in its favor. Thanks!

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.

2 participants