From patchwork Thu Nov 2 10:28:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 833289 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySM8w3PWTz9sRW for ; Thu, 2 Nov 2017 21:42:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="ElRpo392"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3ySM8w25dVzDrD8 for ; Thu, 2 Nov 2017 21:42:08 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="ElRpo392"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=23.83.222.37; helo=cockroach.ash.relay.mailchannels.net; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="ElRpo392"; dkim-atps=neutral Received: from cockroach.ash.relay.mailchannels.net (cockroach.ash.relay.mailchannels.net [23.83.222.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3ySM4N0t6KzDr67 for ; Thu, 2 Nov 2017 21:38:10 +1100 (AEDT) X-Sender-Id: mxroute|x-authuser|stephen@that.guru Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 79D04368EC2 for ; Thu, 2 Nov 2017 10:29:09 +0000 (UTC) Received: from one.mxroute.com (unknown [100.96.131.5]) (Authenticated sender: mxroute) by relay.mailchannels.net (Postfix) with ESMTPA id 00EE5367CC9 for ; Thu, 2 Nov 2017 10:29:08 +0000 (UTC) X-Sender-Id: mxroute|x-authuser|stephen@that.guru Received: from one.mxroute.com (one-outgoing.mxroute.com [172.20.66.218]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.9.14); Thu, 02 Nov 2017 10:29:09 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: mxroute|x-authuser|stephen@that.guru X-MailChannels-Auth-Id: mxroute X-Robust-Towering: 77d093ab3778dfee_1509618549259_1107434865 X-MC-Loop-Signature: 1509618549259:3410384442 X-MC-Ingress-Time: 1509618549258 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qQk+c1mH2iWBHJbXebFRx28Y5qKQej2P2vCL+oEvyik=; b=ElRpo3925fKXYtQ4StZ/st7ET2 BVmZ/xxlDXukhgpLEKldu3AE8mSWsza8+VAyZt17bAX8vkfKhuf9UIKZw5gfaL/gFcwQ4sYGmSbae Lz04SU7GDkZMOJy1/uE4sf24Dx+X1piILA4zof+vk/Ihq8GR1kUL59ZEyJJPBozRjlaf22SlIOACF EwBdss5+Qh5zlWJPE2D8z5Ry/40CQjDNZZQHz8H6LQOGbFMCA9qZiDzmScnC151zJ3349R1zHCw18 yPy6H6PAdhR+IvoUHMxyNzDGDhUWBWQV/JDl7Y1qiTX6oXTVQ309YAZ5z+D2z12/9mBXbMYACW09D zo5m54jA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 6/9] REST: Allow for mutability of request.POST Date: Thu, 2 Nov 2017 10:28:41 +0000 Message-Id: <20171102102844.18931-7-stephen@that.guru> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102102844.18931-1-stephen@that.guru> References: <20171102102844.18931-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Using Django 1.11 yields the following error for the 'patchwork.tests .test_rest_api.TestCheckAPI.test_create' test: AttributeError: This QueryDict instance is immutable This occurs due to our modification of data to allow users to create instances using a slugified state instead of the underlying integer value, e.g. 'success' instead of 1. Resolve this by unsetting the immutability of that queryset. As suggested in the linked SO answer, there is limited side effects to doing this. Signed-off-by: Stephen Finucane --- patchwork/api/check.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 5b381505..b37d6e01 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -49,7 +49,16 @@ class CheckSerializer(HyperlinkedModelSerializer): def run_validation(self, data): for val, label in Check.STATE_CHOICES: if label == data['state']: + # 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 + # to fix what we need to here. + # + # [1] http://stackoverflow.com/a/12619745/613428 + mutable = data._mutable # noqa + data._mutable = True # noqa data['state'] = val + data._mutable = mutable # noqa break return super(CheckSerializer, self).run_validation(data)