Fix viewset actions dict being mutated after first request#9853
Open
mag123c wants to merge 4 commits intoencode:mainfrom
Open
Fix viewset actions dict being mutated after first request#9853mag123c wants to merge 4 commits intoencode:mainfrom
mag123c wants to merge 4 commits intoencode:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the original actions dictionary passed to ViewSet.as_view() was being mutated after the first request, specifically by adding a 'head' key when a 'get' action was present.
- Creates a copy of the actions dictionary before any modifications
- Updates all internal references to use the copied dictionary
- Adds a regression test to ensure the original dictionary remains unchanged
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rest_framework/viewsets.py | Creates a copy of the actions dict (bound_actions) before modification and uses it for all internal operations, preventing mutation of the original dict |
| tests/test_viewsets.py | Adds a regression test to verify the original actions dict is not mutated after calling as_view() or making requests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fix the original
actionsdict passed toViewSet.as_view()being mutated after the first request.refs #9747