Giter Club home page Giter Club logo

drf-rw-serializers's People

Contributors

amandasavluchinske avatar amitgaru2 avatar barseghyanartur avatar dependabot[bot] avatar fjsj avatar g1sky avatar guglielmo avatar hebertjulio avatar hmpf avatar hugobessa avatar luzfcb avatar nnsnodnb avatar pamella avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drf-rw-serializers's Issues

when i use Read & Write Serializers

  • drf-rw-serializers version:
  • Django version:
  • Python version:
  • Operating System:

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

How to use drf-rw-serializers in viewsets.ModelViewSet

  • drf-rw-serializers version:
  • Django version:
  • Python version:
  • Operating System:

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

As document said: the view class is base on generics.ListCreateAPIView. and from drf_rw_serializers import generics
But I am using viewsets.ModelViewSet for view class base, how could I enable drf_rw_serializers to my view class?

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Add support for type hints

If yes, any possibility to add support of type hints? as DRF supports type hints but with the usage of this library, all the type checks vanished

swagger/openapi support

  • drf-rw-serializers version: 1.0.1
  • Django version: 2.1
  • Python version: 3.7
  • Operating System: Linux

Description

When I add swagger/openapi view support (with help of drf-yasg for example) I get undesirable/incorrect specification for writable methods (POST, PUT, PATCH), they correspond to read_serializer_class instead of to write_serializer_class.

What I Did

from drf_rw_serializers import viewsets

class MyViewSet(viewsets.ModelViewSet):
    read_serializer_class = serializers.ReadSerializer
    write_serializer_class = serializers.WriteSerializer

To fix that problem I suggest to add something along the following lines:

    def get_serializer_class(self):
        if self.request.method in ['GET']:
            return self.get_read_serializer_class()
        return self.get_write_serializer_class()

Hopefully I provided sufficient amount of information.

Thank you for your efforts.

Assertion error when used only with `get_serializer_class()` implementation

  • drf-rw-serializers version: 1.2.0 + (I guess)
  • Django version: 4.2.13
  • Python version: 3.11.9
  • Operating System: Linux / MacOS

Description

We are currently in the middle of migration to RW serializers, meaning some viewsets has get_read/write_serializer_class implemented and some using old approach (1 serializer) which end-up being served from get_serializer_class. With the latest changes if the class implements get_serializer_class and does not implement serializer_class attribute, then assertion error raised.

What I Did

Below I will try to post the simple code snippet

class MyApiViewSet(drf_rw_serializers_viewsets.GenericViewSet[MyModel]):
    queryset = MyModel.objects.all()

    @typing_extensions.override
    def get_serializer_class(self) -> type[drf_serializers.BaseSerializer[MyModel]:
        serializer_class:type[drf_serializers.BaseSerializer[MyModel] | None = None
        if self.action == 'action_one':
            serializer_class = SomeSerializer
        if serializer_class is None:
            msg = f'Unknown action: {self.action}'
            raise ValueError(msg)
        return serializer_class

This snippet is very good to find out if you are missing any serializer for any action (especially it is done during schema generation).

This code was not producing any errors in 1.1.x version but produces this in 1.2.x+:

AssertionError: 'MyApiViewSet' should either include one of `serializer_class` and
`read_serializer_class` attribute, or override one of the `get_serializer_class()`,
`get_read_serializer_class()` method.

We do override get_serializer_class but apparently in the RW serializer sources it is not checked.

UPDATE:

Okay, the issue is a little bit different.

In our codebase we are calling self.get_wirte_serializer (note that we do not have write_serializer_class attribute, we do not have get_write_serializer_class method, we rely only on get_serializer_class in this case.

Stack trace is the following:

  File "/home/user/app/src/application/view.py", line 123, in some_method
    serializer = self.get_write_serializer(data=data)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/venv/lib/python3.11/site-packages/drf_rw_serializers/generics.py", line 96, in get_write_serializer
    serializer_class = self.get_write_serializer_class()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/venv/lib/python3.11/site-packages/drf_rw_serializers/generics.py", line 109, in get_write_serializer_class
    return self._get_serializer_class()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/venv/lib/python3.11/site-packages/drf_rw_serializers/generics.py", line 23, in _get_serializer_class
    self.serializer_class is not None

Please note that the error is about read somehow:

'MyApiViewSet' should either include one of `serializer_class` and `read_serializer_class` attribute, or override one of the `get_serializer_class()`, `get_read_serializer_class()` method.

Usage failure

  • drf-rw-serializers version: 0.1.0
  • Django version: 2.0.3
  • Python version: 3.6.4
  • Operating System: macOS High Sierra 10.13.3

Description

Read/write serializers not being called. I've traced it into generics.py, but don't see it going through the mixins ever...

What I Did

I implemented drf-rw-serializers, put them in installed apps, imported them and went through your usage documentation.

Quit the server with CONTROL-C.                                                                                                                                                                                                                                                 
Internal Server Error: /                                                                                                                                                                                                                                                        
Traceback (most recent call last):                                                                                                                                                                                                                                              
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner                                                                                                                                                   
    response = get_response(request)                                                                                                                                                                                                                                            
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response                                                                                                                                               
    response = self.process_exception_by_middleware(e, request)                                                                                                                                                                                                                 
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response                                                                                                                                               
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/views.py", line 494, in dispatch
    response = self.handle_exception(exc)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/views.py", line 454, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/views.py", line 491, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/schemas/views.py", line 31, in get
    schema = self.schema_generator.get_schema(request, self.public)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 286, in get_schema
    links = self.get_links(None if public else request)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 324, in get_links
    link = view.schema.get_link(path, method, base_url=self.url)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py", line 182, in get_link
    fields += self.get_serializer_fields(path, method)
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py", line 302, in get_serializer_fields
    serializer = view.get_serializer()
  File "/Users/user/workspace/django-dapi/lib/python3.6/site-packages/rest_framework/generics.py", line 112, in get_serializer
    return serializer_class(*args, **kwargs)
TypeError: 'NoneType' object is not callable

The documentation page is not available

  • drf-rw-serializers version: 1.01
  • Django version: 2.2
  • Python version: 3.7
  • Operating System: Windows 10 64-bit (Build 17763)

Description

  • the documentation pages is not available when i tried to open it
  • when I want to try the demo via example_app an error appears such as 500 internal server error
  • also, I have migrated the example_app but I am still instructed to migrate again

Any suggest or idea to help with this? Thanks before

Support Python 3.7

Description

Since Python 3.7 is the latest Python release, it would be great if the projects tox and Travis configs were updated to test on it.

License inconsistency

  • drf-rw-serializers version: master

Description

The contents of LICENSE.txt and setup.py are not in agreement about which license this project is released under.

LICENSE.txt contains the MIT license text, while the Trove classifiers in setup.py (which are used to tag/classify the package on PyPI) claims the license is AGPL 3.0. These licenses are not compatible - it would be prudent to resolve this, as many projects would avoid dependencies that are licensed with AGPL.

Added support for Django 2.2

  • drf-rw-serializers version: 1.0.1
  • Django version: 2.2
  • Python version: 3.6
  • Operating System: Mac OS 10.14

Description

When support for Django 2.2 released?

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Migrate deprecated model-mommy to model-bakery

  • drf-rw-serializers version:
  • Django version:
  • Python version:
  • Operating System:

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

New version 1.2.0 require to upgrade djangorestframework

  • drf-rw-serializers version: move from 1.1.1 to 1.2.0
  • Django version: 4.2.13
  • Python version: 3.11.9
  • Operating System: Linux

Description

When we are trying to update the dependency (dependabot), it is failing because it wants to update djangorestframework==3.15.1 as well. We are not upgrading as we have some breaking changes there.

There is no indication that exactly this version is required and before there were no issues. I guess the setup with poetry brings something...

What I Did

As drf-rw-serializers does not depend on specific version of DRF, installation of new version of the library should not try to update DRF version.

NOTE: we are using ruff's UV, but I guess it should not be the reason...

(venv) server@ad9c683d6e80:~/app$ uv pip freeze | grep -E "(drf-rw-serializers=|djangorestframework=)"
djangorestframework==3.14.0
drf-rw-serializers==1.1.1

(venv) server@ad9c683d6e80:~/app$ uv pip install drf_rw_serializers==1.2.0
Resolved 5 packages in 322ms
Installed 2 packages in 22ms
 - djangorestframework==3.14.0
 + djangorestframework==3.15.1
 - drf-rw-serializers==1.1.1
 + drf-rw-serializers==1.2.0

(venv) server@ad9c683d6e80:~/app$ uv pip freeze | grep -E "(drf-rw-serializers=|djangorestframework=)"
djangorestframework==3.15.1
drf-rw-serializers==1.2.0

Remove `<3.1` requirement

  • drf-rw-serializers version: latest
  • Django version: --
  • Python version: --
  • Operating System: --

Description

I think there's not much gain in pinning an upper version requirement for Django specially since it's a minor version. I think we should either remove the upper limit or make it <4.0

What I Did


Can't open API in web browser

  • drf-rw-serializers version: 1.0.4
  • Django version: 3.2.7
  • Python version: 3.8.10
  • Operating System: Ubuntu 20.04.3 LTS

Description

Hi there! So the problem is mentioned in the tittle of the issue.
Requests from terminal works fine, like http GET http://127.0.0.1:8000/api/v1/users/ and POST aswell,
but in browser instead of standard DRF page i get TypeError.

Environment:


Request Method: GET
Request URL: http://localhost:8000/api/v1/users/

Django Version: 3.2.7
Python Version: 3.8.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'users_app.apps.UsersAppConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/rest_framework/response.py", line 70, in rendered_content
    ret = renderer.render(self.data, accepted_media_type, context)
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/rest_framework/renderers.py", line 724, in render
    context = self.get_context(data, accepted_media_type, renderer_context)
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/rest_framework/renderers.py", line 655, in get_context
    raw_data_post_form = self.get_raw_data_form(data, view, 'POST', request)
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/rest_framework/renderers.py", line 554, in get_raw_data_form
    serializer = view.get_serializer()
  File "/home/andy/programming/drf/users/env/lib/python3.8/site-packages/rest_framework/generics.py", line 110, in get_serializer
    return serializer_class(*args, **kwargs)

Exception Type: TypeError at /api/v1/users/
Exception Value: 'NoneType' object is not callable

My views.py

from django.contrib.auth.models import User
from users_app.serializers import ReadOnlyUserSerializer, WriteOnlyUserSerializer
from drf_rw_serializers import generics


class UsersList(generics.ListCreateAPIView):
    queryset = User.objects.all()
    read_serializer_class = ReadOnlyUserSerializer
    write_serializer_class = WriteOnlyUserSerializer

Serializers and other app code must be fine, since it works correctly with usual generic classes.

What I Did

Adding serializer_class = ReadOnlyUserSerializer line to my views solves the problem, but this solution seems weird to me.
I've read docs about installation and usage at https://drf-rw-serializers.readthedocs.io/en/latest/,
still can't figure out what am i missing.
Any help appreciated.

ImportError: No module named drf-rw-serializers

  • drf-rw-serializers version:
    drf-rw-serializers==1.0.1

  • Django version:
    Django==1.11.13
    django-filter==1.1.0

  • Python version:
    2.7.10

  • Operating System:
    Mac OS 10.14.2

Description

When I run runserver to start my app, it reports:
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
ImportError: No module named drf-rw-serializers

What I Did

run : pip install drf-rw-serializers
Add 'drf-rw-serializers', to INSTALLED_APPS of setting file.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

version 1.0.5 not available on pypi.org

Hello in the documentation site it states that there is a version 1.0.5 that supports Django 4 but it's not available on pypi.org. Can you please release it?

Thank you

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.