BrowsableAPIRenderer, Testing and 204 No Content #9423
Unanswered
josepdecid
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have encountered a problem testing an endpoint that should return a
204status.After some debugging, I found that the problem comes from the DRF renderer classes. With the renderer
BrowsableAPIRenderer, it renders the API page where you can see that the response status is HTTP204as it should be. However, testing that endpoint it returns a200. I've tried with Postman and it produces the same response, a200instead of204(Check the screenshot below).The solution was quite simple, I had the
BrowsableAPIRendererbefore theJSONRendererso it was just a matter of changing the order:However, this brings me to the two questions/doubts/thoughts I have:
1 - I think it is an error that the
BrowsableAPIRendererreturns200when the status is204. Sure, the response is not empty because it returns the HTML and a204is not semantically correct, but in my opinion it should be consistent, more so when in the rest of the status it works as expected. I've tried to replicate the same with all other20Xstatus codes but it seems that204is the only one that is causing issues. I have also tried with the40Xand no problems either (haven't tried all status codes but I expect that all the others work properly).2 - I find it odd that someone would want to test the result of the
BrowsableAPIRendererand not the JSON itself. I think the tests could default to using theJSONRendererand always have the option to change it if required (this one is perhaps a bit more controversial).Any thoughts on my 2 takes? Especially the first one.
I'm open to opening an issue if we end up considering that if it is a problem, and I could look into fixing it myself if need be.
Beta Was this translation helpful? Give feedback.
All reactions