Fix WeakSequence.__getitem__ catching KeyError instead of IndexError#13136
Open
bysiber wants to merge 2 commits intosqlalchemy:mainfrom
Open
Fix WeakSequence.__getitem__ catching KeyError instead of IndexError#13136bysiber wants to merge 2 commits intosqlalchemy:mainfrom
bysiber wants to merge 2 commits intosqlalchemy:mainfrom
Conversation
WeakSequence._storage is a list, which raises IndexError on out-of-range access. The except block was catching KeyError, making it dead code — the original IndexError always propagated unhandled.
Member
|
hi, I would just remove the try / except here, since there is no need to re-raise the same type of exception |
Author
|
Good call, simplified it — removed the try/except entirely since |
sqla-tester
reviewed
Feb 21, 2026
Collaborator
sqla-tester
left a comment
There was a problem hiding this comment.
OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision ceb8f9f of this pull request into gerrit so we can run tests and reviews and stuff
Collaborator
|
New Gerrit review created for change ceb8f9f: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6603 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
WeakSequence.__getitem__catchesKeyErrorbut the internal_storageis alist, which raisesIndexErrorfor out-of-range access. This means theexcept KeyErrorhandler never executes, and the custom error message is never shown.Current behavior
On an out-of-range index, the raw
IndexErrorfrom list access propagates directly (e.g.,list index out of range) instead of the intended custom message.Fix
Changed
except KeyErrortoexcept IndexErrorso the handler actually catches the exception raised by list indexing.