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.
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
Fix MRO to return 405 for unsupported methods #3175
Changes from 2 commits
178c6c6
3728854
fd2d0a2
65604e1
646d5c8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 👍