From nobody Fri Apr 26 11:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552998314574452.2710093684258; Tue, 19 Mar 2019 05:25:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40CE32D7ED; Tue, 19 Mar 2019 12:25:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 322081001E61; Tue, 19 Mar 2019 12:25:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EC7E6247DF; Tue, 19 Mar 2019 12:25:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JCPBb1024930 for ; Tue, 19 Mar 2019 08:25:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C8B45C298; Tue, 19 Mar 2019 12:25:11 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-24.ams2.redhat.com [10.36.112.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11A945C28C for ; Tue, 19 Mar 2019 12:25:07 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Tue, 19 Mar 2019 13:25:06 +0100 Message-Id: <20190319122506.3904-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2] models: return None from MessageManager query methods X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 19 Mar 2019 12:25:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Otherwise, we get 500 errors on series views such as https://patchew.org/XYZ/abc@def/ or message views such as https://patchew.org/XYZ/abc@def/ghi@jkl/. Signed-off-by: Paolo Bonzini --- api/models.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/api/models.py b/api/models.py index 7d1b609..23470b8 100644 --- a/api/models.py +++ b/api/models.py @@ -328,26 +328,38 @@ class MessageManager(models.Manager): pass =20 def project_messages(self, project): - q =3D super(MessageManager, self).get_queryset() + po =3D None if isinstance(project, str): - po =3D Project.objects.get(name=3Dproject) + po =3D Project.objects.filter(name=3Dproject).first() elif isinstance(project, int): - po =3D Project.objects.get(id=3Dproject) + po =3D Project.objects.filter(id=3Dproject).first() + if not po: + return None + + q =3D super(MessageManager, self).get_queryset() q =3D q.filter(project=3Dpo) | q.filter(project__parent_project=3D= po) return q =20 def series_heads(self, project=3DNone): if project: q =3D self.project_messages(project) + if not q: + return None else: q =3D super(MessageManager, self).get_queryset() return q.filter(is_series_head=3DTrue).prefetch_related('propertie= s', 'project') =20 def find_series(self, message_id, project_name=3DNone): - return self.series_heads(project_name).filter(message_id=3Dmessage= _id).first() + heads =3D self.series_heads(project_name) + if not heads: + return None + return heads.filter(message_id=3Dmessage_id).first() =20 def find_message(self, message_id, project_name): - return self.project_messages(project_name).filter(message_id=3Dmes= sage_id).first() + messages =3D self.project_messages(project_name) + if not messages: + return None + return messages.filter(message_id=3Dmessage_id).first() =20 def patches(self): return super(MessageManager, self).get_queryset().filter(is_patch= =3DTrue) --=20 2.20.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel