diff options
| author | Susan Dreher | 2015-01-27 16:18:51 -0500 | 
|---|---|---|
| committer | Susan Dreher | 2015-01-27 16:18:51 -0500 | 
| commit | 8c3f82fb18a58b8e0983612ef3cc35b3c3950b66 (patch) | |
| tree | f20362c16d420200a983cadf88e99a24de1b775c /rest_framework | |
| parent | fc70c0862ff3e6183b79adc4675a63874261ddf0 (diff) | |
| download | django-rest-framework-8c3f82fb18a58b8e0983612ef3cc35b3c3950b66.tar.bz2 | |
:bug: ManyRelatedField get_value clearing field on partial update
A PATCH to a serializer's non-related CharField was clearing an ancillary StringRelatedField(many=True) field.
The issue appears to be in the ManyRelatedField's get_value method, which was returning a [] instead of empty
when the request data was a MultiDict.
This fix mirrors code in fields.py, class Field, get_value, Ln. 272, which explicitly returns empty on a partial update.
Tests added to demonstrate the issue.
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/relations.py | 5 | 
1 files changed, 5 insertions, 0 deletions
| diff --git a/rest_framework/relations.py b/rest_framework/relations.py index aa0c2def..13793f37 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -338,7 +338,12 @@ class ManyRelatedField(Field):          # We override the default field access in order to support          # lists in HTML forms.          if html.is_html_input(dictionary): +            # Don't return [] if the update is partial +            if self.field_name not in dictionary: +                if getattr(self.root, 'partial', False): +                    return empty              return dictionary.getlist(self.field_name) +          return dictionary.get(self.field_name, empty)      def to_internal_value(self, data): | 
