[PATCH v2 3/3] migrations: Consider series project when merging series

Stephen Finucane stephen at that.guru
Thu Mar 5 20:27:38 AEDT 2020


We shouldn't attempt to merge series associated with different projects.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Related: #340
---
v2:
- Use 'project' value from 'SeriesReference.series', not
  'SeriesReference'
---
 patchwork/migrations/0039_unique_series_references.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/patchwork/migrations/0039_unique_series_references.py b/patchwork/migrations/0039_unique_series_references.py
index c8ac0dc6..495c0e57 100644
--- a/patchwork/migrations/0039_unique_series_references.py
+++ b/patchwork/migrations/0039_unique_series_references.py
@@ -6,6 +6,13 @@ from django.utils import six
 
 
 def merge_duplicate_series(apps, schema_editor):
+    Project = apps.get_model('patchwork', 'Project')
+
+    for project in Project.objects.values('id'):
+        _merge_duplicate_series(apps, schema_editor, project=project['id'])
+
+
+def _merge_duplicate_series(apps, schema_editor, project):
     SeriesReference = apps.get_model('patchwork', 'SeriesReference')
     Patch = apps.get_model('patchwork', 'Patch')
 
@@ -14,9 +21,10 @@ def merge_duplicate_series(apps, schema_editor):
     # find all SeriesReference that share a msgid but point to different series
     # and decide which of the series is going to be the authoritative one
     msgid_counts = (
-        SeriesReference.objects.values('msgid')
+        SeriesReference.objects.filter(series__project_id=project)
         .annotate(count=Count('msgid'))
         .filter(count__gt=1)
+        .values('msgid')
     )
     for msgid_count in msgid_counts:
         msgid = msgid_count['msgid']
-- 
2.24.1



More information about the Patchwork mailing list