Update generics.py

Fix GenericAPIView.get_serializer(self, *args, **kwargs) ignores context in kwargs and replaces it (which may be used by views) with its default context
This commit is contained in:
MohamadReza Taalebi 2020-01-27 15:36:29 +03:30 committed by GitHub
parent d22daf4e05
commit fa78886581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,7 +106,14 @@ class GenericAPIView(views.APIView):
deserializing input, and for serializing output. deserializing input, and for serializing output.
""" """
serializer_class = self.get_serializer_class() serializer_class = self.get_serializer_class()
kwargs['context'] = self.get_serializer_context()
# Include view's costum context
default_context = self.get_serializer_context()
if 'context' in kwargs:
kwargs['context'].update(default_context)
else:
kwargs['context'] = default_context
return serializer_class(*args, **kwargs) return serializer_class(*args, **kwargs)
def get_serializer_class(self): def get_serializer_class(self):