fix(types): coerce non-str inputs in parse_type - #2575
Conversation
Accept None/int-ish exporter field values without TypeError when normalizing SQL types via sqlglot.
|
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)
Walkthrough
ChangesType parsing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 1
🧹 Nitpick comments (2)
core/wren/src/wren/type_mapping.py (2)
41-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAlign the type annotations with the accepted inputs.
parse_typenow intentionally acceptsNoneand arbitrary non-string values, but its signature remainsstr, forcing callers and tests to usetype: ignore. Update the public annotations and docstring to reflect the defensive boundary.Suggested annotation update
-def parse_type(type_str: str, dialect: str) -> str: +def parse_type(type_str: object, dialect: object) -> str:🤖 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/type_mapping.py` around lines 41 - 48, Update the public parse_type annotations to accept None and arbitrary non-string type_str values, and adjust its docstring to document this defensive coercion behavior; keep the existing normalization logic unchanged.
47-53: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd regression coverage for invalid dialects.
The implementation adds dialect normalization and
TypeErrorfallback, but the supplied tests cover only type values. Add a test for non-string and invalid string dialects, verifying the no-raise/fallback contract against sqlglot 29.0.0.🤖 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/type_mapping.py` around lines 47 - 53, Add regression tests for the type-mapping function around dialect handling, covering both non-string dialect values and invalid string dialects. Verify against sqlglot 29.0.0 that each case does not raise and returns the expected fallback/result, while preserving the existing type-value test coverage.
🤖 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_type_mapping.py`:
- Around line 383-388: Update test_parse_type_none_and_non_str to assert that
parse_type(38, "postgres") returns the exact string "38" instead of only
checking truthiness, while retaining the existing type assertion.
---
Nitpick comments:
In `@core/wren/src/wren/type_mapping.py`:
- Around line 41-48: Update the public parse_type annotations to accept None and
arbitrary non-string type_str values, and adjust its docstring to document this
defensive coercion behavior; keep the existing normalization logic unchanged.
- Around line 47-53: Add regression tests for the type-mapping function around
dialect handling, covering both non-string dialect values and invalid string
dialects. Verify against sqlglot 29.0.0 that each case does not raise and
returns the expected fallback/result, while preserving the existing type-value
test coverage.
🪄 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: 6167a64a-b7aa-4962-be95-e02f74768329
📒 Files selected for processing (2)
core/wren/src/wren/type_mapping.pycore/wren/tests/unit/test_type_mapping.py
|
Good call — tightened the assertion to check the exact stringified fallback ( |
|
Closing this as-is — one half is arguable, the other is an unrelated behavior change. The The if not isinstance(dialect, str) or not dialect:
dialect = ""This silently swaps the SQL dialect for sqlglot's default whenever a caller passes something unexpected, which changes how types parse rather than guarding against a crash — and it isn't mentioned in the title or description. A wrong-dialect parse that returns a plausible-looking type is much harder to debug than a Adding If you'd like to pursue the |
|
Agreed on all three points. The |
Summary
None→ empty string and non-str raw types viastr(...)inparse_typeTypeErrorfrom sqlglotLicense
Apache-2.0 (
core/**).Motivation
Dynamic schema exporters sometimes emit
null/numeric type placeholders.parse_typeassumed a string and crashed start-up mapping paths.Verification
cd core/wren && .venv/bin/python -m pytest tests/unit/test_type_mapping.py::test_parse_type_none_and_non_str tests/unit/test_type_mapping.py::test_parse_types_none_type_field -v— 2 passedDuplicate check
type_mapping.parse_typenon-str coercionSummary by CodeRabbit
Bug Fixes
Tests
Noneand non-string inputs for type parsing.