From patchwork Wed Mar 4 17:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 1249139 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48XgmY182gz9sNg for ; Thu, 5 Mar 2020 04:27:09 +1100 (AEDT) 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" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=default header.b=RwPgr/Pu; 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 48XgmX3GlszDqck for ; Thu, 5 Mar 2020 04:27:08 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=that.guru (client-ip=199.181.239.185; helo=relay0185.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" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=default header.b=RwPgr/Pu; dkim-atps=neutral Received: from relay0185.mxlogin.com (relay0185.mxlogin.com [199.181.239.185]) (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 48XgmS1cbkzDqSC for ; Thu, 5 Mar 2020 04:27:03 +1100 (AEDT) Received: from filter004.mxroute.com ([149.28.56.236] 149.28.56.236.vultr.com) (Authenticated sender: mN4UYu2MZsgR) by relay0185.mxlogin.com (ZoneMTA) with ESMTPSA id 170a69611e2000c6c5.001 for (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Wed, 04 Mar 2020 17:26:57 +0000 X-Zone-Loop: 6f641ef9412cc80ac5d14b70624d21f0a91a7f5e83d5 X-Originating-IP: [149.28.56.236] Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter004.mxroute.com (Postfix) with ESMTPS id C4CB33EA20; Wed, 4 Mar 2020 17:26:56 +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=BchVPxVqlw1iHsuV4p9JswS/O/Nq5X5Mmkpk+zwhA6I=; b=RwPgr/PuXsB22VtHaAgWEq9U/9 RhCqdb9uUp2Xs+zkvF76rGKnfoe1dHM61g2x+NlgDybCxUUFA5HBq7GIxs/RfDwAPra4UI6/i8qaf AXf8qIhIusi2N+J9Fb56uG/rVSn/W99xsa13xomqUx8KLWiGzQg8eZDiURbCaGMNqE9n1ov716JWi gAqkCH2kkJXSwVCnOVl6gjf+kGbIyLBetf2qj5sgD44HE4T5DYlUe6aataDS1Jjhcdx/sPYWFrP0z M6qldrpkv5bNfFeoFlmQt/y/+XC25Y1wA7Q4twwLiFppdFUS2fCWYpUlqQuNvnt5wBwiSQpJPtL4f YKb8d7FQ==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 2/3] migrations: Don't fail if it's not possible to rehome a patch Date: Wed, 4 Mar 2020 17:26:45 +0000 Message-Id: <20200304172646.49409-2-stephen@that.guru> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200304172646.49409-1-stephen@that.guru> References: <20200304172646.49409-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" Migration 0039 attempts to move patches that have ended up in an arbitrary series due to race conditions into the correct series. However, because we weren't previously considering versions when choosing a series, this might not be possible resulting in the issues seen in #340 [1]. If this happens, we could try rehome _those_ patches but that's really complicated and requires bringing in a whole load of parsing functionality from 'patchwork.parser' so we can e.g. rebuild the list of references from the headers. Instead, print a big warning to the admin with information about how they could fix the issue and then just remove the offending references. This means we're still left with orphaned series but these could be fixed manually, if necessary. [1] https://github.com/getpatchwork/patchwork/issues/340 Signed-off-by: Stephen Finucane Closes: #340 --- .../0039_unique_series_references.py | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/patchwork/migrations/0039_unique_series_references.py b/patchwork/migrations/0039_unique_series_references.py index 99b10fcc..c8ac0dc6 100644 --- a/patchwork/migrations/0039_unique_series_references.py +++ b/patchwork/migrations/0039_unique_series_references.py @@ -1,6 +1,8 @@ from django.db import connection, migrations, models from django.db.models import Count +from django.db.utils import IntegrityError import django.db.models.deletion +from django.utils import six def merge_duplicate_series(apps, schema_editor): @@ -49,14 +51,41 @@ def merge_duplicate_series(apps, schema_editor): if series_ref == chosen_ref: continue + has_conflict = False + # update the patches to point to our chosen series instead, on the # assumption that all other metadata is correct for patch in Patch.objects.filter(series=series_ref.series): patch.series = chosen_ref.series - patch.save() + try: + patch.save() + except IntegrityError as exc: + has_conflict = True + print( + "We attempted to merge patch '%d' into the correct " + "series, '%d', but it appears there is already a " + "patch with the same number in this series. We have " + "deleted the series references for the bad series, " + "'%d', but you may wish to do further manual work to " + "resolve this issue. For more information, refer to " + "https://git.io/JvVvV. Error: %s" % ( + patch.id, + chosen_ref.series.id, + series_ref.series.id, + six.text_type(exc), + ) + ) - # delete the other series (which will delete the series ref) - series_ref.series.delete() + if not has_conflict: + # assuming there has been no conflict and all patches have been + # moved to a new series, delete the other series (which will + # delete the series ref) + series_ref.series.delete() + else: + # otherwise just delete the series references and keep the old + # series for later cleanup + for series_ref in series_ref.series.references: + series_ref.delete() def copy_project_field(apps, schema_editor):