-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing context to serializer with request
param causes AttributeError
on query_params
#128
Comments
What is the point of using a DRF serialier with a standard request? I mean: you should know when you are in an |
In my case, I was using the serializer outside of a DRF API view. I like to re-use serializers sometimes for functionality outside the API. |
In that case the "fix" is simple: from rest_framwork.request import Request
...
MySerializer(data, context={'request': Request(request)}) Since you are using this outside rest framework "middleware" I belive it is normal that you should provide the appropriated changes. |
Aha, fair enough. Although usually serializers work fine with Django request objects. Just not when using FlexFields. So when you're introducing But I understand your reasoning as well. We could also check if |
To solve that the easiest fix would be to make flex-fields use |
Aha yeah that sounds like a good idea. Then it doesn't have a dependency on DRF request objects, and it can just work with common Django request objects. |
When you create a Serializer like this:
Then I get the following error:
Because drf-flex-fields relies on the
query_params
that is provided by theHttpRequest
wrapper of Django Rest FrameworkBut if you create a serializer manually, and pass the request object into the context, then we have a regular Django HttpRequest object, which does not contain the
query_params
property.The issue can be resolved like this:
Maybe we can incorporate this in some way into drf-flex-field?
The text was updated successfully, but these errors were encountered: