Closed
Description
When raising a subclass of APIException
(for example ValidationError
or ParseError
) from a ViewSet
, 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:
# views.py
class MyViewSet(viewsets.GenericViewSet):
...
@action(methods=['post'], detail=False, url_path='bulk-create')
def bulk_create(self, request, *args, **kwargs):
# Some assertion about data structure
if True:
raise ParseError("Expected the data to be in list format.")
# Actually process incoming data
...
Error log:
Traceback (most recent call last):
2022-05-17T12:23:45.366216553Z File "/opt/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
2022-05-17T12:23:45.366221178Z response = get_response(request)
2022-05-17T12:23:45.366223345Z File "/opt/venv/lib/python3.9/site-packages/debug_toolbar/middleware.py", line 67, in __call__
2022-05-17T12:23:45.366225470Z panel.generate_stats(request, response)
2022-05-17T12:23:45.366238220Z File "/opt/venv/lib/python3.9/site-packages/debug_toolbar/panels/request.py", line 30, in generate_stats
2022-05-17T12:23:45.366240470Z "post": get_sorted_request_variable(request.POST),
2022-05-17T12:23:45.366346803Z File "/opt/venv/lib/python3.9/site-packages/debug_toolbar/utils.py", line 227, in get_sorted_request_variable
2022-05-17T12:23:45.366352511Z return [(k, variable.getlist(k)) for k in sorted(variable)]
2022-05-17T12:23:45.366354803Z TypeError: '<' not supported between instances of 'dict' and 'dict'
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.
Metadata
Metadata
Assignees
Labels
No labels