From patchwork Sat Jun 8 17:36:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 1112505 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 45LmmT2JdKz9sBb for ; Sun, 9 Jun 2019 03:36:57 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru 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="etIfTPHV"; 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 45LmmT0nDhzDqwY for ; Sun, 9 Jun 2019 03:36:57 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=199.181.239.192; helo=relay0192.mxlogin.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru 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="etIfTPHV"; dkim-atps=neutral Received: from relay0192.mxlogin.com (relay0192.mxlogin.com [199.181.239.192]) (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 45Lmm22zsgzDqv6 for ; Sun, 9 Jun 2019 03:36:33 +1000 (AEST) Received: from filter002.mxroute.com (unknown [94.130.183.33]) by relay0192.mxlogin.com (Postfix) with ESMTP id 36373CC80248 for ; Sat, 8 Jun 2019 12:36:30 -0500 (CDT) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 6C95B3F0D2 for ; Sat, 8 Jun 2019 17:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=caDDkJq4ihsELNHDI6wHl2apLLshDiBtQqnHCjhmSvg=; b=etIfTPHVSNEbDqPw3QZEGmIT7J qdNxh7vN5GB73blkH13JD09h9sgd9V+a/cEqRJr2FW2WodrJ/GHiLQECPi64JCeLpCRKPxO+ev2t3 yUbqTtw1K50o/Mwug6h1Q1XKCDGZduhI6sGEfOpvIpPWpvvqGQ4TXN2YVkHv3bFqdAOBi1LibNzj2 yLKEcWHN0gB5VKIhuhtdWb94FgdcY8Eoa9REULe2BCZVNukIsR1Eww0Rd9oJb8MXy3r42TlF+yGJ3 Rb6vZf9pxgwHTagbQ1LYJKHJP2O1rc7QinCd3AJGeUQYgmpHeqwBr027E0JWWfOXVjFTU3ZtV7NnD XYNzntyQ==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v3 1/5] forms: Don't attempt to evaluate State at startup Date: Sat, 8 Jun 2019 18:36:18 +0100 Message-Id: <20190608173622.6711-2-stephen@that.guru> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190608173622.6711-1-stephen@that.guru> References: <20190608173622.6711-1-stephen@that.guru> MIME-Version: 1.0 X-AuthUser: stephen@that.guru 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" As was designed, starting the interpreter would cause the State model and its entries to be evaluated. This was an issue if, for example, the model had been modified and you were attempting to apply the migration. Traceback (most recent call last): File "manage.py", line 11, in execute_from_command_line(sys.argv) ... File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py", line 1199, in _set_queryset self.widget.choices = self.choices File "/home/patchwork/patchwork/patchwork/forms.py", line 157, in _get_choices super(OptionalModelChoiceField, self)._get_choices()) File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py", line 1143, in __len__ return (len(self.queryset) + (1 if self.field.empty_label is not None else 0)) File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 232, in __len__ self._fetch_all() File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1118, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 53, in __iter__ results = compiler.execute_sql(chunked_fetch=self.chunked_fetch) File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 899, in execute_sql raise original_exception django.db.utils.OperationalError: (1054, "Unknown column 'patchwork_state.slug' in 'field list'") Resolve this by moving the evaluation into '__init__', meaning it will only occur when a new form is created. Signed-off-by: Stephen Finucane --- patchwork/forms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patchwork/forms.py b/patchwork/forms.py index 5d4c920a..5690eb01 100644 --- a/patchwork/forms.py +++ b/patchwork/forms.py @@ -165,7 +165,6 @@ class OptionalBooleanField(forms.TypedChoiceField): class MultiplePatchForm(forms.Form): action = 'update' - state = OptionalModelChoiceField(queryset=State.objects.all()) archived = OptionalBooleanField( choices=[('*', 'no change'), ('True', 'Archived'), ('False', 'Unarchived')], @@ -176,6 +175,8 @@ class MultiplePatchForm(forms.Form): super(MultiplePatchForm, self).__init__(*args, **kwargs) self.fields['delegate'] = OptionalModelChoiceField( queryset=_get_delegate_qs(project=project), required=False) + self.fields['state'] = OptionalModelChoiceField( + queryset=State.objects.all()) def save(self, instance, commit=True): opts = instance.__class__._meta