]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Handle JSON requests
authorStephen Finucane <stephen@that.guru>
Tue, 30 Apr 2019 06:03:02 +0000 (16:03 +1000)
committerStephen Finucane <stephen@that.guru>
Tue, 30 Apr 2019 17:36:44 +0000 (11:36 -0600)
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.

NOTE(daxtens): This is needed for JSON bodies sent by regular users, not
just the tests.

Signed-off-by: Stephen Finucane <stephen@that.guru>
(cherry picked from commit dc48fbce99efe7d13987a3f510f7dee389636eba)

patchwork/api/check.py

index d76573a528ec3d61cdb9694baeffb8e22e378d71..67062132fef3cd55cbd561d97fef6cd7951e2e4b 100644 (file)
@@ -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):