From: Stephen Finucane <step...@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 <step...@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 <d...@axtens.net> --- patchwork/api/check.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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): -- 2.19.1 _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork