Comments (6)
What is the point of using a DRF serialier with a standard request?
I mean: you should know when you are in an APIView
(or @api_view
) or not, if not you should take care of providing the right argument to the serializer.
from drf-flex-fields.
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.
from drf-flex-fields.
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.
from drf-flex-fields.
Aha, fair enough. Although usually serializers work fine with Django request objects. Just not when using FlexFields. So when you're introducing FlexFieldsModelSerializer
or FlexFieldsSerializerMixin
in your code, you can suddenly have this issue, and you would need to figure out what the problem is and apply the fix to potentially multiple spots in your code. People might think that FlexFields just doesn't work for their use-case, or with their version of Django / DRF.
But I understand your reasoning as well. We could also check if query_params
exists, and if not, raise a custom exception with a descriptive error message so the user understands it should wrap the Django Request object in a Rest Framework Request object.
from drf-flex-fields.
To solve that the easiest fix would be to make flex-fields use request.GET
instead of request.query_params
(which is just an alias property).
from drf-flex-fields.
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.
from drf-flex-fields.
Related Issues (20)
- FlexFieldsFilterBackend does not handle "GenericForeignKey" HOT 2
- 0.9.9 not available on Pypi? HOT 1
- Expand Argument Not Respected When Empty HOT 1
- Release 1.0.0 available on PyPI but not listed in GIthub Releases, and not tagged
- is_expanded does not take into account the wildcard "*" (default) or setting "WILDCARD_VALUES"
- maximum depth of expansion (dot notation) / avoid infinite recursion HOT 2
- <module_path_to_serializer_class>.RelatedSerializer? HOT 1
- _get_expandable_fields() returns a list but is used by get_schema_fields() to concatenate str
- Swagger does not work when add FlexFieldsFilterBackend in my view
- Potential Denial of Service HOT 2
- support Django 4.2 and drf 3.14??? HOT 3
- Applying distinct to `fields`
- Does "deferred field" imply under-the-hood `.defer()`? HOT 2
- Support for a list of expansions with multiple expand parameters instead of separated by a comma. HOT 1
- Support lazily evaluating expanded serializer class from a function
- Custom EXPAND_PARAM not usable in Serializer options HOT 1
- Enhancement Request: Support default expansion and omission of fields per drf view or action HOT 1
- Enhancement: magic field expansion
- OpenAPI support for query parameters HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-flex-fields.