You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using NestedViewSetMixin with request.data as a list, the method initialize_request raises a TypeError.
TypeError: list indices must be integers or slices, not str
Cause
The error occurs because the method assumes request.data is always a dictionary, but in cases where the request contains a list, this assumption fails.
Steps to reproduce
Define a view using NestedViewSetMixin and ModelViewSet.
Create an action that receives a list in the request data.
Send a POST request to the action with a list in the payload.
Example:
class NestedClass(NestedViewSetMixin, ModelViewSet):
parent_lookup_kwargs = ...
queryset = ...
serializer_class = ...
@action(detail=False, methods=["post"])
def some_action(self, request, *args, **kwargs):
# request.data is a list
...
Possible Fix
A possible fix to this could be to add the parent params on each element.
The text was updated successfully, but these errors were encountered:
When using
NestedViewSetMixin
withrequest.data
as a list, the methodinitialize_request
raises aTypeError
.Cause
The error occurs because the method assumes request.data is always a dictionary, but in cases where the request contains a list, this assumption fails.
Steps to reproduce
Example:
Possible Fix
A possible fix to this could be to add the parent params on each element.
The text was updated successfully, but these errors were encountered: