From: Stephen Finucane Date: Fri, 7 Dec 2018 12:13:32 +0000 (+0000) Subject: REST: Handle JSON requests X-Git-Tag: v2.2.0-rc1~195 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc48fbce99efe7d13987a3f510f7dee389636eba;p=thirdparty%2Fpatchwork.git 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 --- diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 0e35bd45..1f9fe068 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):