Skip to content

PATCH with no data is updating ListField values on ModelSerializer instead of leaving them alone #2761

@picturedots

Description

@picturedots

I've got a model serializer with two ListFields and an email field in it, something like this

class MySettingsSerializer(ModelSerializer):
    location_codes = serializers.ListField(child=serializers.CharField(), 
        required=False)
    permissions = serializers.ListField(child=serializers.CharField(), 
        required=False )

    class Meta:
        model = MySettings
        fields = ('id', 'email', 'location_codes', 'permissions' )

I've also got a view class that uses UpdateModelMixin to provide an update method.

When I do a PATCH to to my view, the expected behavior is that only the values that are sent will be changed. For example, PATCH with
{"permissions": [ "change_mymodel" ] }
should change the permissions field on the MySettings object, and not change any of the other fields. This works as expected.

However, if I do a PATCH with no data at all, both the permissions and locations_codes are set to empty lists. The other field (email) is not changed, which leads me to believe that there is bug related to identifying if a ListField should be updated during a PATCH.

Note that this issue cannot be triggered by the HTML form interface by PATCHING a {} -- I can only see it by using a client like Postman and doing a PATCH with no content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy