From nobody Sat Dec 21 12:27:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=patchew-devel-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1645942448; cv=none; d=zohomail.com; s=zohoarc; b=WuyCBxTbE1wRkTYWH9AlWSR7JnWZWzaU/1WnTLFVA9kKeilmi0XSKJmKQmMwYZLw5qE2JjBQi9yUwZfKlnkKIePBfwFtcx0OGQ4qKMQoHEfIcVUE6iQX1xrFHxweepibYR4C3D6xgIUxiys9U9++z9UxGJb+q+NSFlZbnpwOM98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645942448; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=L9u8eUwm3zYSffFUA7FQThxlfTwImltLK1KwEIUquEY=; b=lXmgtBatFIk5aj25N7vFDkT7rgtw867ZmeEcL8EZipOAXJtxyMLn1Z4PWvBwx0e85S3/cu4HJ5frelwM6LHxW8WVdtN7OHCW3gbURJbf7LqtQVWx1MbrjZ4xQIELSDkDYRBL5qYUUrGp59ZMjD0TbFa+RW9iMpjvPXtydgphhLE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1645942448010440.95152948639395; Sat, 26 Feb 2022 22:14:08 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-572-82S8legPOfG5_HUbg9Mv4Q-1; Sun, 27 Feb 2022 01:14:02 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98CE780205C; Sun, 27 Feb 2022 06:14:01 +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 9078479595; Sun, 27 Feb 2022 06:14:01 +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 8934318087F0; Sun, 27 Feb 2022 06:14:01 +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 21R6DsDI017089 for ; Sun, 27 Feb 2022 01:13:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 42D0B7A22F; Sun, 27 Feb 2022 06:13:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9823979595 for ; Sun, 27 Feb 2022 06:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645942446; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=L9u8eUwm3zYSffFUA7FQThxlfTwImltLK1KwEIUquEY=; b=SiRroTqvTso8OkKKPBLB0UA0H8axR9c2lUK4B9lPVJV8U0r4Fywh4uK2VJmhizqJ/rZHTY Pn/UTacDCFPohhXTu6rh1dMIlWrHIhfVpCavpuTJyLxTRvubBeE9K6evlKYWoM5V0FEVdy jI7wErj521RJYGD8LJ14Mecs34M+IsQ= X-MC-Unique: 82S8legPOfG5_HUbg9Mv4Q-1 From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sun, 27 Feb 2022 07:13:27 +0100 Message-Id: <20220227061327.37066-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] rest: ignore IntegrityErrors on message import 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: , Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=patchew-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1645942450054100009 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- api/rest.py | 13 ++++++++----- tests/test_rest.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/rest.py b/api/rest.py index 43ec79d..8117ddc 100644 --- a/api/rest.py +++ b/api/rest.py @@ -690,14 +690,17 @@ class MessagesViewSet(BaseMessageViewSet): projects =3D (p for p in projects if p.maintained_by(self.requ= est.user)) results =3D [] for project in projects: - serializer =3D self.get_serializer(data=3Drequest.data) - serializer.is_valid(raise_exception=3DTrue) - serializer.save(project=3Dproject) - results.append(serializer.data) + try: + serializer =3D self.get_serializer(data=3Drequest.data) + serializer.is_valid(raise_exception=3DTrue) + serializer.save(project=3Dproject) + results.append(serializer.data) + except django.db.utils.IntegrityError: + pass # Fake paginator response. Note that there is no Location header. return Response( OrderedDict([("count", len(results)), ("results", results)]), - status=3Dstatus.HTTP_201_CREATED, + status=3Dstatus.HTTP_201_CREATED if results else status.HTTP_2= 00_OK, ) =20 =20 diff --git a/tests/test_rest.py b/tests/test_rest.py index aaa9dd0..9d96fa4 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -638,7 +638,7 @@ class RestTest(PatchewTestCase): resp =3D self.api_client.post( self.REST_BASE + "messages/", data, content_type=3D"message/rf= c822" ) - self.assertEqual(resp.status_code, 201) + self.assertEqual(resp.status_code, 200) self.assertEqual(resp.data["count"], 0) resp_get =3D self.api_client.get( self.PROJECT_BASE --=20 2.34.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://listman.redhat.com/mailman/listinfo/patchew-devel