Open
Conversation
+ add documentation for change strategy
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a browsable API crash for ViewSet extra actions by preventing object-level permission checks when generating the synthetic OPTIONS form metadata (issue #6855).
Changes:
- Special-case
OPTIONShandling inBrowsableAPIRenderer.get_rendered_html_form()to avoid object-level permission checks againstserializer.instance. - Add regression coverage reproducing the crash scenario for extra actions returning
serializer.data. - Add a guardrail test ensuring
DELETEform rendering still respects object-level permission checks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
rest_framework/renderers.py |
Adjusts browsable API form generation to skip object-permission checks for synthetic OPTIONS placeholders. |
tests/test_renderers.py |
Adds regression tests for issue #6855 and verifies DELETE still enforces object permissions. |
Comments suppressed due to low confidence (1)
rest_framework/renderers.py:515
- The new OPTIONS special-casing duplicates
show_form_for_method()logic (allowed_methods + permission check) and makes the laterif method in ('DELETE', 'OPTIONS')branch effectively unreachable for OPTIONS. Consider reusingshow_form_for_method(view, method, request, obj=None)here (to skip object permissions) and then simplifying the later condition to only handle DELETE, to keep the control flow in one place and avoid future divergence.
if method == 'OPTIONS':
# The browsable API only needs a placeholder for OPTIONS, so
# avoid object-level permission checks against serializer.instance.
if method not in view.allowed_methods:
return
try:
view.check_permissions(request)
except exceptions.APIException:
return
return True
if not self.show_form_for_method(view, method, request, instance):
return
if method in ('DELETE', 'OPTIONS'):
return True # Don't actually need to return a form
💡 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.
refs #6855
Summary
OPTIONSform metadata in the browsable API.DELETE/edit permission behavior unchanged.Test plan
.venv/bin/pytest tests/test_renderers.py::BrowsableAPIRendererTests