From nobody Wed Apr 24 00:43: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 1552907816336831.1443272824037; Mon, 18 Mar 2019 04:16:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10B86308425A; Mon, 18 Mar 2019 11:16:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05A6E61D07; Mon, 18 Mar 2019 11:16:55 +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 EC4C4181A12B; Mon, 18 Mar 2019 11:16:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2IBGrE4002568 for ; Mon, 18 Mar 2019 07:16:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 208165D70D; Mon, 18 Mar 2019 11:16:53 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FFFB5D707 for ; Mon, 18 Mar 2019 11:16:50 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Mon, 18 Mar 2019 12:16:49 +0100 Message-Id: <20190318111649.9106-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 18 Mar 2019 11:16:55 +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 | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/api/models.py b/api/models.py index 7d1b609..41228df 100644 --- a/api/models.py +++ b/api/models.py @@ -329,25 +329,43 @@ class MessageManager(models.Manager): =20 def project_messages(self, project): q =3D super(MessageManager, self).get_queryset() - if isinstance(project, str): - po =3D Project.objects.get(name=3Dproject) - elif isinstance(project, int): - po =3D Project.objects.get(id=3Dproject) + try: + if isinstance(project, str): + po =3D Project.objects.get(name=3Dproject) + elif isinstance(project, int): + po =3D Project.objects.get(id=3Dproject) + except Project.DoesNotExist: + return None 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 + try: + return heads.filter(message_id=3Dmessage_id).first() + except Message.DoesNotExist: + return None + =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 + try: + return messages.filter(message_id=3Dmessage_id).first() + except Message.DoesNotExist: + return None =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