diff mbox series

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

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

Commit Message

Stephen Finucane March 5, 2020, 9:27 a.m. UTC
We shouldn't attempt to merge series associated with different projects.

Signed-off-by: Stephen Finucane <stephen@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 mbox series

Patch

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']