fix: skip non-model types in __change_field_name#2717
Conversation
WalkthroughThe fix prevents the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ 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: 0
🧹 Nitpick comments (1)
src/datamodel_code_generator/parser/base.py (1)
1808-1809: Consider using an explicit type check instead of checking BASE_CLASS.The guard
if not model.BASE_CLASS:works but is indirect. SinceTypeAliasBaseis already imported (line 65), consider using an explicit type check for clarity and safety:if "Enum" in model.base_class: continue - if not model.BASE_CLASS: + if isinstance(model, TypeAliasBase): continueThis makes the intent clearer (skip type aliases from field name transformation) and avoids potential
AttributeErrorifBASE_CLASSdoesn't exist on some model types.🔎 Verify which model types lack BASE_CLASS
#!/bin/bash # Check if BASE_CLASS is consistently defined across DataModel subclasses ast-grep --pattern $'class $CLASS($$$): $$$ BASE_CLASS = $$$ $$$'
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/datamodel_code_generator/parser/base.py(1 hunks)tests/data/expected/main/graphql/union_snake_case_field.py(1 hunks)tests/main/graphql/test_main_graphql.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/main/graphql/test_main_graphql.py (2)
tests/test_main_kr.py (1)
output_file(44-46)tests/main/conftest.py (2)
output_file(94-96)run_main_and_assert(196-352)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: py312-isort7 on Ubuntu
- GitHub Check: py312-isort5 on Ubuntu
- GitHub Check: 3.10 on Ubuntu
- GitHub Check: 3.11 on Ubuntu
- GitHub Check: 3.12 on Ubuntu
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.14 on Windows
- GitHub Check: Analyze (python)
- GitHub Check: benchmarks
🔇 Additional comments (1)
tests/main/graphql/test_main_graphql.py (1)
606-615: LGTM! Test correctly validates the fix.The test properly verifies that union type references are not converted to snake_case when
--snake-case-fieldis enabled. The test uses the sameunion.graphqlinput as the existingtest_main_graphql_uniontest but with the--snake-case-fieldflag andpydantic_v2.BaseModeloutput type, which is exactly what's needed to validate the fix for issue #2405.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2717 +/- ##
=======================================
Coverage 99.34% 99.34%
=======================================
Files 82 82
Lines 11611 11615 +4
Branches 1405 1406 +1
=======================================
+ Hits 11535 11539 +4
Misses 45 45
Partials 31 31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #2717 will not alter performanceComparing Summary
Footnotes
|
Fixes: #2405
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.