Skip to content

fix(memory): skip non-dict models/columns in seed query generation#2542

Open
Bartok9 wants to merge 3 commits into
Canner:mainfrom
Bartok9:fix/seed-queries-skip-nonduct-columns
Open

fix(memory): skip non-dict models/columns in seed query generation#2542
Bartok9 wants to merge 3 commits into
Canner:mainfrom
Bartok9:fix/seed-queries-skip-nonduct-columns

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • generate_seed_queries skips non-dict models/relationships.
  • _model_seeds filters non-dict / nameless columns before reading col["name"].

License

Apache-2.0 (core/wren).

Verification

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

Test plan

  • unit test mixed manifest
  • CI green

Summary by CodeRabbit

  • Bug Fixes
    • Improved seed query generation to safely handle manifests with missing or unexpected shapes, including malformed model, column, and relationship entries.
    • Prevents failures when invalid entries are present, while continuing to produce valid seed queries.
  • Tests
    • Added unit coverage ensuring malformed models/columns are skipped and that generated outputs include expected SQL content.

@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: 3d2e4706-1d14-4851-89bd-f472d3d90f0b

📥 Commits

Reviewing files that changed from the base of the PR and between e3edbe1 and 2c8c5dd.

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

Walkthrough

Seed query generation now validates manifest models, relationships, and columns before processing them. Invalid entries are skipped, malformed collections are treated as empty, and unit coverage verifies valid model seeds remain generated.

Changes

Seed query robustness

Layer / File(s) Summary
Manifest model and relationship guards
core/wren/src/wren/memory/seed_queries.py
Model and relationship collections are normalized, invalid entries are skipped, and relationship key extraction handles malformed input.
Column filtering and validation
core/wren/src/wren/memory/seed_queries.py, core/wren/tests/unit/test_seed_queries_nonduct.py
Malformed column metadata is filtered before seed derivation, with tests covering invalid models and columns while preserving valid orders seed output.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • Canner/WrenAI#2424: Hardens related manifest and relationship parsing in seed generation.
  • Canner/WrenAI#2514: Directly relates to malformed column handling in _model_seeds.
  • Canner/WrenAI#2541: Hardens malformed model, relationship, and column traversal in related schema processing.

Suggested labels: python, core

Suggested reviewers: goldmedal

Poem

I’m a rabbit guarding seeds in a row,
Skipping strange shapes that should not grow.
Models hop past, columns behave,
Valid orders seeds are safely saved.
Relationships tumble, but none cause fright—
The query garden stays just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 matches the main change: defensively skipping non-dict models and columns during seed query generation.
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/seed_queries.py (2)

55-56: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Simplify redundant dictionary fallbacks.

The or [] fallback and [] default argument are unnecessary because the subsequent isinstance(rels, list) checks naturally evaluate to False for None or other non-list types, safely bypassing the logic.

  • core/wren/src/wren/memory/seed_queries.py#L55-L56: simplify to rels = manifest.get("relationships")
  • core/wren/src/wren/memory/seed_queries.py#L177-L179: simplify to rels = manifest.get("relationships")
🤖 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/seed_queries.py` around lines 55 - 56, Simplify
both relationship lookups in core/wren/src/wren/memory/seed_queries.py at lines
55-56 and 177-179 by removing the redundant [] fallbacks and assigning
manifest.get("relationships") directly; leave the subsequent isinstance(rels,
list) checks unchanged so non-list values bypass processing safely.

34-46: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Extract valid models to avoid redundant iteration and strictly check for string names.

Iterating over models once to extract a list of valid_models simplifies the logic and removes duplicated checks.

Additionally, verifying that the model name is a string provides complete safety. The current is not None check allows non-string values (like numbers or booleans) through, which would still result in a runtime AttributeError when _norm_ident subsequently calls .strip(). Finally, the or [] default fallback can be safely omitted since the isinstance check naturally handles None.

♻️ Proposed refactor
-    models = manifest.get("models", []) or []
-    if not isinstance(models, list):
-        models = []
-    model_layers = {
-        model["name"]: _prop_value(model, "dbtLayer", "dbt_layer")
-        for model in models
-        if isinstance(model, dict) and model.get("name") is not None
-    }
-    relationship_keys = _relationship_key_columns(manifest)
-
-    for model in models:
-        if not isinstance(model, dict) or model.get("name") is None:
-            continue
+    models = manifest.get("models")
+    if not isinstance(models, list):
+        models = []
+
+    valid_models = [
+        model for model in models
+        if isinstance(model, dict) and isinstance(model.get("name"), str)
+    ]
+
+    model_layers = {
+        model["name"]: _prop_value(model, "dbtLayer", "dbt_layer")
+        for model in valid_models
+    }
+    relationship_keys = _relationship_key_columns(manifest)
+
+    for model in valid_models:
🤖 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/seed_queries.py` around lines 34 - 46, In the
model-processing flow, replace the separate model-layer comprehension and later
validation loop with one extraction of valid_models. Treat manifest["models"] as
invalid unless it is a list, without relying on an or [] fallback, and retain
only dictionary entries whose name is a string. Use valid_models for both
model_layers construction and subsequent processing so validation is not
duplicated and _norm_ident cannot receive non-string names.
🤖 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/seed_queries.py`:
- Around line 71-74: Update the column normalization logic to use the raw value
from model.get("columns", []) without the redundant “or []” fallback, retain the
list-type guard, and filter entries only when c.get("name") is a string.
Preserve the existing dictionary validation while preventing malformed
non-string names from reaching _norm_ident.

---

Nitpick comments:
In `@core/wren/src/wren/memory/seed_queries.py`:
- Around line 55-56: Simplify both relationship lookups in
core/wren/src/wren/memory/seed_queries.py at lines 55-56 and 177-179 by removing
the redundant [] fallbacks and assigning manifest.get("relationships") directly;
leave the subsequent isinstance(rels, list) checks unchanged so non-list values
bypass processing safely.
- Around line 34-46: In the model-processing flow, replace the separate
model-layer comprehension and later validation loop with one extraction of
valid_models. Treat manifest["models"] as invalid unless it is a list, without
relying on an or [] fallback, and retain only dictionary entries whose name is a
string. Use valid_models for both model_layers construction and subsequent
processing so validation is not duplicated and _norm_ident cannot receive
non-string names.
🪄 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: 0abe0a7a-0752-4673-920c-6768fcfe35b3

📥 Commits

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

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

Comment thread core/wren/src/wren/memory/seed_queries.py Outdated
Guards against malformed column names (int/bool) that pass 'is not None'
but fail on _norm_ident .strip(). Addresses CodeRabbit review on Canner#2542.
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