Assert context not in kwargs

Raise and AssertionError whenever a `context` argument is passed to the `get_serializer`
This commit is contained in:
MohamadReza Taalebi 2020-01-28 03:38:31 +03:30 committed by GitHub
parent 4602333f6e
commit ad99b8e253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,14 +106,13 @@ class GenericAPIView(views.APIView):
deserializing input, and for serializing output.
"""
serializer_class = self.get_serializer_class()
# Include view's custom context
default_context = self.get_serializer_context()
if 'context' in kwargs:
kwargs['context'].update(default_context)
else:
kwargs['context'] = default_context
assert 'context' not in kwargs, (
"`get_serializer` does not accept a `context` argument, "
"you may override `get_serializer_context` instead."
)
kwargs['context'] = self.get_serializer_context()
return serializer_class(*args, **kwargs)
def get_serializer_class(self):