-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
PATCH with no data is updating ListField values on ModelSerializer instead of leaving them alone #2761
Comments
Sounds valid - it'd be good to pull together a more minimal example case that uses a regular serializer rather than a model serializer - that'd help us progress the issue. |
Hello from DjangoCon sprints. Working on proof of concept solution for this issue. Should have a PR to you in a few days. |
@adamsc64 Welcome onboard ! It would be wonderfull to start with a failing test case first in order to prove the issue and make sure the fix actually fixes the issue. |
- When not submitting key for list fields or multiple choice, partial serialization should result in empty state (key not there), not an empty list.
- Checked ``partial`` state immediately; return ``empty`` if key not submitted. - Previously, partial serialization for updates, such as in the case of HTTP PATCH requests, would truncate any old values for ListField. This is because it had relied on the default value of an empty list. But an empty list has different functionality than the sentinal value of ``empty``.
- When not submitting key for list fields or multiple choice, partial serialization should result in empty state (key not there), not an empty list.
- Checked ``partial`` state immediately; return ``empty`` if key not submitted. - Previously, partial serialization for updates, such as in the case of HTTP PATCH requests, would truncate any old values for ListField. This is because it had relied on the default value of an empty list. But an empty list has different functionality than the sentinal value of ``empty``.
- Checked ``partial`` state when getting value in appropriate field classes; return ``empty`` immediately if key not submitted.
- Checked ``partial`` state when getting value in appropriate field classes; return ``empty`` immediately if key not submitted.
- When not submitting key for list fields or multiple choice, partial serialization should result in empty state (key not there), not an empty list.
@xordoquy @tomchristie: I've submitted PR #3415 linked above. Let me know what you think or what else you need from me! |
Fixed #2761 - ListField truncation on HTTP PATCH
I've got a model serializer with two ListFields and an email field in it, something like this
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.
The text was updated successfully, but these errors were encountered: