Fix IndexError when using --reuse-scope=tree with single file output#2954
Fix IndexError when using --reuse-scope=tree with single file output#2954
Conversation
📝 WalkthroughWalkthroughFilter out empty/falsy module entries when validating shared module names to avoid indexing into empty tuples; add a test asserting an error is raised when using Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)tests/main/openapi/test_main_openapi.py (2)
⏰ 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). (10)
🔇 Additional comments (1)
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 |
|
📚 Docs Preview: https://pr-2954.datamodel-code-generator.pages.dev |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @tests/main/openapi/test_main_openapi.py:
- Around line 4944-4965: The test function
test_main_openapi_reuse_scope_tree_single_file_error uses a Pydantic v2-specific
model flag but is missing the @SKIP_PYDANTIC_V1 decorator; add the
@SKIP_PYDANTIC_V1 decorator immediately above the test function definition to
skip this test in Pydantic v1 environments so it only runs when Pydantic v2 is
available (no other changes to test body or args).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tests/data/openapi/issue_2953.yamlis excluded by!tests/data/**/*.yamland included by none
📒 Files selected for processing (2)
src/datamodel_code_generator/parser/base.pytests/main/openapi/test_main_openapi.py
⏰ 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). (11)
- GitHub Check: 3.10 on Ubuntu
- GitHub Check: 3.14 on Windows
- GitHub Check: 3.10 on macOS
- GitHub Check: 3.10 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.11 on macOS
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.12 on macOS
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (1)
src/datamodel_code_generator/parser/base.py (1)
1755-1755: LGTM! Correctly prevents IndexError for empty module tuples.The added
if modulefilter prevents anIndexErrorwhenmoduleis an empty tuple(). Since empty modules have no name, they cannot conflict withshared_module_name, so filtering them out is both safe and semantically correct. This fix resolves issue #2953 where using--reuse-scope treewith single-file output could trigger this error.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2954 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 94 94
Lines 17723 17726 +3
Branches 2037 2037
=========================================
+ Hits 17723 17726 +3
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:
|
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This PR is a pure bug fix. The change adds a filter This analysis was performed by Claude Code Action |
|
🎉 Released in 0.53.0 This PR is now available in the latest release. See the release notes for details. |
Fixes: #2953
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.