From patchwork Tue Apr 30 06:03:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1092998 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44tWGk3Q7jz9s7T for ; Tue, 30 Apr 2019 16:05:34 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="eXn9P5A5"; 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 44tWGj6XvJzDqRL for ; Tue, 30 Apr 2019 16:05:33 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="eXn9P5A5"; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44tWDT0k1jzDqMm for ; Tue, 30 Apr 2019 16:03:36 +1000 (AEST) Received: by mail-pf1-x42d.google.com with SMTP id z26so2653924pfg.6 for ; Mon, 29 Apr 2019 23:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rmfpnAcONdApz9T0CjrXVYAmCK5FvcdeVVmyZU59GKQ=; b=eXn9P5A5BU3vkRfSTDxfRrq1HmGS7S+oEZ3Qv4nD2Kw7pL7t+FXxwTnaJDOPFUHStX avhiUDFaM3xbasFMN9cKSIjdziS5vdbFB8u7ay7lEzWHBgEwr87qC69qhhnqWR+P8gc/ JPLUPYy3aYCRN/2FegDWMgff7pL0+Ge+wyPqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rmfpnAcONdApz9T0CjrXVYAmCK5FvcdeVVmyZU59GKQ=; b=ocM7S1b1Go0UlUcWmPQaO6tlekJe5TmNM8Zrfj34R1ZhSLuaAkQz9IiG/2SQbZoybQ +9kYFdHUDsDvFqDXiAzZp/+CcnbXHZql962YVqaYsOwiVhjUsPlfMEdMzXajtoCdEK9p wYeGSbzNwQ70ldLn7UILubBKsVMp6Hrc1bZ3xZhl6uQLqojEpxj9btco2xF8QXY2L5YK 8v9GE49NpURG4R5uMnKL9YmwpnlF27KRY+zk9t5cNBOZdLnCaHAP6sf+QSnrlJ2m5ZJ+ xreqlHd5ygh3/HaiKDv9t7JTCyAauLBX1Lf7bdeg14QeDhciZ5kCNqk6oRpCN06ucs2A nk8Q== X-Gm-Message-State: APjAAAUuaT+hlR1dd/2UnO6dFB0muIkAV5o5dDHENGgcjtK/rHWW98+K 5R8dyC923dZ+Y7YIjgj+qBKLs6ZUfFw= X-Google-Smtp-Source: APXvYqys7/h4IqGpXnF6cjyXa0nTTlsMhdy+afEvFxFvArLxSLOgxcqIG7uI1Rq5j0TcY2Aqx8mCjQ== X-Received: by 2002:a65:5342:: with SMTP id w2mr45427859pgr.220.1556604214357; Mon, 29 Apr 2019 23:03:34 -0700 (PDT) Received: from localhost (203-217-53-131.dyn.iinet.net.au. [203.217.53.131]) by smtp.gmail.com with ESMTPSA id e184sm55166084pfc.102.2019.04.29.23.03.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Apr 2019 23:03:33 -0700 (PDT) From: Daniel Axtens To: patchwork@lists.ozlabs.org Subject: [PATCH 04/10] REST: Handle JSON requests Date: Tue, 30 Apr 2019 16:03:02 +1000 Message-Id: <20190430060308.10432-5-dja@axtens.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190430060308.10432-1-dja@axtens.net> References: <20190430060308.10432-1-dja@axtens.net> MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" From: Stephen Finucane 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 (cherry picked from commit dc48fbce99efe7d13987a3f510f7dee389636eba This is needed for JSON bodies sent by regular users, not just the tests.) Signed-off-by: Daniel Axtens --- 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):