Message ID | 20190430060308.10432-5-dja@axtens.net |
---|---|
State | Accepted |
Headers | show |
Series | Patchwork 2.1.2 review series | expand |
On Tue, 2019-04-30 at 16:03 +1000, Daniel Axtens wrote: > From: Stephen Finucane <stephen@that.guru> > > This was raising an attribute error when switching tests to use JSON > bodies instead of form-data. > > AttributeError: 'dict' object has no attribute '_mutable' > > The easy fix is to check if it's a dictionary and avoid the mutability > check if so. > > Signed-off-by: Stephen Finucane <stephen@that.guru> > (cherry picked from commit dc48fbce99efe7d13987a3f510f7dee389636eba > This is needed for JSON bodies sent by regular users, not just the > tests.) > Signed-off-by: Daniel Axtens <dja@axtens.net> Applied.
diff --git a/patchwork/api/check.py b/patchwork/api/check.py index d76573a528ec..67062132fef3 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -50,7 +50,12 @@ class CheckSerializer(HyperlinkedModelSerializer): def run_validation(self, data): for val, label in Check.STATE_CHOICES: - if label == data['state']: + if label != data['state']: + continue + + if isinstance(data, dict): # json request + data['state'] = val + else: # form-data request # NOTE(stephenfin): 'data' is essentially 'request.POST', which # is immutable by default. However, there's no good reason for # this to be this way [1], so temporarily unset that mutability @@ -61,7 +66,8 @@ class CheckSerializer(HyperlinkedModelSerializer): data._mutable = True # noqa data['state'] = val data._mutable = mutable # noqa - break + + break return super(CheckSerializer, self).run_validation(data) def to_representation(self, instance):