From patchwork Thu Apr 16 01:29:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1271469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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 492hX247qxz9sSb for ; Thu, 16 Apr 2020 11:31:30 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=DqnKdPf9; 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 492hX23KcmzDqdm for ; Thu, 16 Apr 2020 11:31:30 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (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 492hVc6D7JzDqK9 for ; Thu, 16 Apr 2020 11:30:16 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=DqnKdPf9; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 492hVc4DHzz9sSb; Thu, 16 Apr 2020 11:30:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1587000616; bh=WcRzzryTJnhxFZpt3yolgl5O9x4UAZwkteh1nzEOGhc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DqnKdPf9jtkh/WzOTC1LcsYGh6491NNHp96gK9+tfKOle95a+iKIpsXb8a8zZvQbC hmFcDHPsBYCvHeC8w25ghSZrDNRju/RDPh/bjHANlZplRgG0oYK/apPLE4ADladU/M 23ymCVzGGoSZz96YyCHMmzrNMNO+mC4KEuY4PDxVIF8EdJAEVBhM5rRUBbUP01pp1a chSMnRlS3b2/xStL9iLKQJJIwyctTvtFYwF0831XZKHv6vx0dqN4LBX6W+4MDB41Be 2A1x/biePp5i9b+D3uMVkujzwtA793EEGh7CFbL96TCW3TnRTRlmVxcw2yvLHDONPv WTjiWy9uye2kQ== From: Jeremy Kerr To: patchwork@lists.ozlabs.org Subject: [PATCH 3/5] parser: prevent IntegrityErrors Date: Thu, 16 Apr 2020 09:29:26 +0800 Message-Id: <20200416012928.23893-4-jk@ozlabs.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200416012928.23893-1-jk@ozlabs.org> References: <20200416012928.23893-1-jk@ozlabs.org> 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: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Currently, the parser relies on causing (and catching) IntegrityErrors on patch insert to catch duplicate (msgid,project) mails. This change performs an atomic select -> insert instead. Signed-off-by: Jeremy Kerr --- patchwork/parser.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/patchwork/parser.py b/patchwork/parser.py index a09fd75..e03634a 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -1062,7 +1062,10 @@ def parse_mail(mail, list_id=None): filenames = find_filenames(diff) delegate = find_delegate_by_filename(project, filenames) - try: + with transaction.atomic(): + if Patch.objects.filter(project=project, msgid=msgid): + raise DuplicateMailError(msgid=msgid) + patch = Patch.objects.create( msgid=msgid, project=project, @@ -1077,8 +1080,6 @@ def parse_mail(mail, list_id=None): delegate=delegate, state=find_state(mail)) logger.debug('Patch saved') - except IntegrityError: - raise DuplicateMailError(msgid=msgid) for attempt in range(1, 11): # arbitrary retry count try: