From patchwork Fri Aug 20 14:57:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1519072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=aYIIAgMg; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (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 4GrlBJ4nlbz9sVw for ; Sat, 21 Aug 2021 00:58:16 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GrlBD2VWfz3cGT for ; Sat, 21 Aug 2021 00:58:12 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=aYIIAgMg; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::102d; helo=mail-pj1-x102d.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=aYIIAgMg; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (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 4GrlB93Mnrz3bmm for ; Sat, 21 Aug 2021 00:58:07 +1000 (AEST) Received: by mail-pj1-x102d.google.com with SMTP id mq3so7452162pjb.5 for ; Fri, 20 Aug 2021 07:58:07 -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:mime-version :content-transfer-encoding; bh=e/rYNxDggzDn1I24vheMh8Xn6BUXtEmvnuETvPVFPXQ=; b=aYIIAgMgss2vFxnHEsoRWqW6Y0FiXBQcApXECf1ec5rWuqzZLiNRg5OoisCOslbvtL 86MSbkBJtUdkJel+2de+xWnVorIvVIWpgZDKcbYKf9mx6F9L606AmcbTlo97xU2Ymm+t r7afpE1PodYyFsF0MfXhy5+K8FfSsSlH9e4Mc= 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:mime-version :content-transfer-encoding; bh=e/rYNxDggzDn1I24vheMh8Xn6BUXtEmvnuETvPVFPXQ=; b=cafNuKYeoXyKTYqN7L4HQveBsAuY93HXoMZxibF7RmMf3u7rmkq+WFCZZ1fzHvBlMy otC7InaKNDZANXdnkrt/5vRPLvVmZc+WaqGGamNwh0ixje7jJ62hsVwk97kkGZ0qUH1n oKtB56HHEbCWIR7IJx4V2T0DWKRBfYl7oIWYFE3CDAriCSofdVSDWFKkry0PgaS8V07x iiNl1IFOt1Wt+ht0+yrf+vxTiMe9re1D3aRcdPwT+s6g0URNGAAgkRNXNn/pM2J8rK97 QApJtMGD1nLuqe+3KAffTaW9acBblIF80RHWDyIna5hXuutJ7VJvqcNb+Qkkb4Zw0zaj 028g== X-Gm-Message-State: AOAM530W7mmPeccxijkQpNHnLMRi7bgyjg4PJALNaaj1GSGT0/zcHw9n r68lOPQkCO422GUmWgJY8t+60TIo8EjXgA== X-Google-Smtp-Source: ABdhPJz9C7/xnTu3RUs+A83rFYacEOO/wYM1RCj3eHWl8vEMpYMNOnes0B9v0a+QTU0D9+sxoRiCPA== X-Received: by 2002:a17:90a:404a:: with SMTP id k10mr5063534pjg.145.1629471484166; Fri, 20 Aug 2021 07:58:04 -0700 (PDT) Received: from localhost ([2001:4479:e000:e400:a871:82f7:c9f:2130]) by smtp.gmail.com with ESMTPSA id g4sm3069265pjt.56.2021.08.20.07.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 07:58:03 -0700 (PDT) From: Daniel Axtens To: patchwork@lists.ozlabs.org Subject: [PATCH 1/2] REST: Don't error if a versioned field we would remove is absent Date: Sat, 21 Aug 2021 00:57:58 +1000 Message-Id: <20210820145759.2180392-1-dja@axtens.net> X-Mailer: git-send-email 2.30.2 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" We remove fields that shouldn't be seen on old versions of the API. This was done with `pop(field name)`, which will throw an exception if the named field is absent from the data. However, sometimes if a patch request is via an old API version, we hit this line without ever having the field present. This is odd, but not harmful and we definitely shouldn't 500. Fixes: d944f17ec059 ("REST: Use versioning for modified responses") Signed-off-by: Daniel Axtens Tested-by: Konstantin Ryabitsev Reviewed-by: Stephen Finucane --- patchwork/api/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/patchwork/api/base.py b/patchwork/api/base.py index 89a43114f9e7..6cb703b12bbb 100644 --- a/patchwork/api/base.py +++ b/patchwork/api/base.py @@ -96,6 +96,9 @@ class BaseHyperlinkedModelSerializer(HyperlinkedModelSerializer): # field was added, we drop it if not utils.has_version(request, version): for field in self.Meta.versioned_fields[version]: - data.pop(field) + # After a PATCH with an older API version, we may not see + # these fields. If they don't exist, don't panic, return + # (and then discard) None. + data.pop(field, None) return data