-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Middleware breaks raising APIException from ViewSet #1621
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
Comments
I think we had a problem like this in the past. We should probably add a fallback somewhere if sorting the data in Are you using django-rest-framework or something similar by chance? Does DRF modify Django's standard |
Yes, I am using DRF version 3.12.4. I just logged |
Can you log/print |
@matthiask it sounds like somehow |
@tim-schilling Yes, it seems like that. I'm confused by @FinnGu What are you POSTing exactly? A JSON document with a list as its outer element? DRF seems to set |
@matthiask Here is the JSON, I am POSTing with
I just tested your assumption and you are correct. It is enough to pass an array with any kind of object in it, to crash the DDT. Is it bad practice to use arrays in RESTful design? Because it is valid JSON. |
@tim-schilling Which variable did you want me to print? I am confused. |
Great, thanks!
I'm not sure. Django's Do what works for you. I'd say that the real problem here is that some library (possibly DRF) changes Here's a draft pull request with a proposed fix for this issue: #1624 |
Your PR solved the issue perfectly, thanks! Also very good advice on using arrays as top-level structure in a REST API. I will rethink my design for that route. EDIT: Apparently Django's testing framework has similar issues with top-level arrays. You just convinced me to wrap everything in an object.... |
When raising a subclass of
APIException
(for exampleValidationError
orParseError
) from aViewSet
, I get a very cryptic error message that suggests that some sort function is broken. When I disable the middleware, everything works as expected.Minimal code example:
Error log:
I have also posted this question on StackOverflow: https://stackoverflow.com/questions/72274329/cannot-raise-apiexception-from-django-viewset
Thank you for your help in advance.
The text was updated successfully, but these errors were encountered: