From: Daniel Axtens Date: Tue, 30 Apr 2019 06:03:03 +0000 (+1000) Subject: REST: Handle regular form data requests for checks X-Git-Tag: v2.1.2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d963655ccd89c68648dbe3b2843a4a7b06aa78ce;p=thirdparty%2Fpatchwork.git REST: Handle regular form data requests for checks 08d1459a4a40 ("Add REST API validation using OpenAPI schema") moved all API requests to JSON blobs rather than form data. dc48fbce99ef ("REST: Handle JSON requests") attempted to change the check serialiser to handle this. However, because both a JSON dict and a QueryDict satisfy isinstance(data, dict), everything was handled as JSON and the old style requests were broken. Found in the process of debugging issues from the OzLabs PW & Snowpatch crew - I'm not sure if they actually hit this one, but kudos to them anyway as we wouldn't have found it without them. NOTE(daxtens): This does not need the new tests as we do not have 08d1459a4a40, so we just need the fix to the API. We do not add a JSON test to stable. Fixes: dc48fbce99ef ("REST: Handle JSON requests") Signed-off-by: Daniel Axtens (cherry picked from commit 666de29ebada5990a8d69f4d71d6bb271e1a68c3) --- diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 67062132..62e6fd19 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -19,6 +19,7 @@ from django.http import Http404 from django.shortcuts import get_object_or_404 +from django.http.request import QueryDict from rest_framework.exceptions import PermissionDenied from rest_framework.generics import ListCreateAPIView from rest_framework.generics import RetrieveAPIView @@ -53,9 +54,7 @@ class CheckSerializer(HyperlinkedModelSerializer): if label != data['state']: continue - if isinstance(data, dict): # json request - data['state'] = val - else: # form-data request + if isinstance(data, QueryDict): # 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 @@ -66,6 +65,8 @@ class CheckSerializer(HyperlinkedModelSerializer): data._mutable = True # noqa data['state'] = val data._mutable = mutable # noqa + else: # json request + data['state'] = val break return super(CheckSerializer, self).run_validation(data)