Generic View context behaviour #8018
Unanswered
filipetavares
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there! I'm opening this discussion to address the way the context is passed to the serializer when using a generic views.
The default behaviour is
kwargs.setdefault('context', self.get_serializer_context())
, i.e: if you pass in any context, it will discard the view context (as per #7298 (comment)). However this behaviour is, in my opinion, a bit confusing. I believe that the expected behaviour should be to append the extra context to the view context, meaning that theview
,request
andformat
should always be expected to appear in the context if the serializer is called by a generic view.We could use the context passed by the user and update it with the view context as suggested by #7162 (comment), or we could get the view context first and then update it with the user context, ensuring that user can override the view context fields if he wishes.
What do you guys think?
Thanks and keep up the good work.
Beta Was this translation helpful? Give feedback.
All reactions