-
Notifications
You must be signed in to change notification settings - Fork 0
Fix IndexError when Pydantic validation error has empty loc tuple #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the WalkthroughAdded defensive guard in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
Comment |
- Fixed bug in runner.py line 80 where accessing [-1] on empty loc tuple caused IndexError - Changed logic to check if loc tuple is empty before accessing last element - Added test case to verify empty loc tuple is handled correctly - All existing tests pass with no regressions Co-authored-by: jreakin <[email protected]>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an IndexError that occurs when Pydantic validation errors contain an empty loc tuple, which can happen with model_validator failures on nested models. The fix adds a defensive check before indexing the tuple and defaults to "unknown" when the location is empty.
Key changes:
- Modified error handling in
runner.pyto safely access theloctuple with an emptiness check - Added comprehensive test coverage for the empty
loctuple edge case
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/abstract_validation_base/runner.py | Fixed IndexError by checking if loc tuple is empty before accessing [-1] index |
| tests/test_runner.py | Added test case verifying that empty loc tuples are handled gracefully with "unknown" default |
The implementation looks solid and follows the existing error handling patterns in the codebase. The fix correctly addresses the bug described in the issue, and the test coverage adequately validates the new behavior. The solution is consistent with the existing fallback to "unknown" when loc is missing entirely, providing uniform behavior across edge cases.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
Pydantic can return empty
loctuples for certain validation failures, particularly withmodel_validatoron nested models. Accessing[-1]on an empty tuple raisesIndexError.Changes
runner.py: Check if
loctuple is empty before indexingtest_runner.py: Add test case for empty
loctuple handlingThe fix defaults to
"unknown"for the field name whenlocis empty, consistent with existing behavior whenlocis missing.Original prompt
loctuple #1💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.