-
Notifications
You must be signed in to change notification settings - Fork 214
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
Fix MRO to return 405 for unsupported methods #3175
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
178c6c6
Fix MRO
dhruvkb 3728854
Convert between DRF and Django request/response types
dhruvkb fd2d0a2
Add test case for unsupported HTTP method
dhruvkb 65604e1
Drop redundant args and kwargs
dhruvkb 646d5c8
Update URL to test the right endpoint
dhruvkb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
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.
Is it necessary to
json.loads
the content? Would something like this work without the need for that?HttpResponse
is the more low-level version fromdjango.http
that allows you to bypass the DRFResponse
data parsing. Doingjson.loads
and then passing it directly toResponse
means we're unnecessary marshalling the JSON string to Python and then immediately back to a string.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.
Although, more general question: why is it necessary to do anything manual here at all, other than just return
res
like we used to? DoesAPIView
complain about not receiving the right type of response object or something?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.
We can use
HttpResponse
for sure, but sending DRF'sResponse
is more consistent and it renders the DRF API UI in the browser like our other endpoints.I agree that it's one more step of JSON parsing followed by serialization but DRF doesn't allow any other way to set data where the
content_type
can be negotiated automatically.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.
Ahh, interesting, I didn't realise that was a side effect. For this view, it doesn't seem like a tragic loss, though? It's not exactly a "browseable" response 🤔 At least not any less so if your browser just renders a nice JSON explorer (Firefox does this, not sure of others).
I also don't think we want to support anyone using this view over anything than JSON anyway, but I guess
Response
handles it regardless so 🤷 I would personally use HttpResponse but if you prefer to keep it, all good with me as well 👍