diff options
author | Stephen Finucane <stephen@that.guru> | 2018-12-07 12:13:32 +0000 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2018-12-22 17:19:06 +0000 |
commit | dc48fbce99efe7d13987a3f510f7dee389636eba (patch) | |
tree | 99143b5e3d75b8a700c77542a9e8b28d38bf3c88 | |
parent | b21ee9f512457da50ece329940bd121d1d59bc99 (diff) | |
download | patchwork-dc48fbce99efe7d13987a3f510f7dee389636eba.tar patchwork-dc48fbce99efe7d13987a3f510f7dee389636eba.tar.gz |
REST: Handle JSON requests
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>
-rw-r--r-- | patchwork/api/check.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 0e35bd4..1f9fe06 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -36,7 +36,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 @@ -47,7 +52,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): |