diff mbox series

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

Message ID 20200304172646.49409-3-stephen@that.guru
State Superseded
Headers show
Series [1/3] parser: Don't group patches with different versions in a series | expand

Commit Message

Stephen Finucane March 4, 2020, 5:26 p.m. UTC
We shouldn't attempt to merge series associated with different projects.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Related: #340
---
 patchwork/migrations/0039_unique_series_references.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/patchwork/migrations/0039_unique_series_references.py b/patchwork/migrations/0039_unique_series_references.py
index c8ac0dc6..e7292bf2 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(project_id=project)
         .annotate(count=Count('msgid'))
         .filter(count__gt=1)
+        .values('msgid')
     )
     for msgid_count in msgid_counts:
         msgid = msgid_count['msgid']