mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
Assert context not in kwargs
Raise and AssertionError whenever a `context` argument is passed to the `get_serializer`
This commit is contained in:
parent
4602333f6e
commit
ad99b8e253
|
@ -106,14 +106,13 @@ 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()
|
||||||
|
|
||||||
# Include view's custom context
|
assert 'context' not in kwargs, (
|
||||||
default_context = self.get_serializer_context()
|
"`get_serializer` does not accept a `context` argument, "
|
||||||
if 'context' in kwargs:
|
"you may override `get_serializer_context` instead."
|
||||||
kwargs['context'].update(default_context)
|
)
|
||||||
else:
|
kwargs['context'] = self.get_serializer_context()
|
||||||
kwargs['context'] = default_context
|
|
||||||
|
|
||||||
return serializer_class(*args, **kwargs)
|
return serializer_class(*args, **kwargs)
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user