Coder Social home page Coder Social logo

Comments (6)

sevdog avatar sevdog commented on September 16, 2024

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.

gitaarik avatar gitaarik commented on September 16, 2024

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.

sevdog avatar sevdog commented on September 16, 2024

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.

gitaarik avatar gitaarik commented on September 16, 2024

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.

sevdog avatar sevdog commented on September 16, 2024

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.

gitaarik avatar gitaarik commented on September 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.