]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Fix series.project migration logic
authorAndy Doan <andy.doan@linaro.org>
Wed, 25 Jan 2017 20:17:29 +0000 (14:17 -0600)
committerStephen Finucane <stephen@that.guru>
Thu, 26 Jan 2017 23:53:28 +0000 (23:53 +0000)
The migration logic seems slightly off for 2 reasons:

1) If you already have series objects in your database, then adding a
non-nullable foreign key to projects will fail.

2) This may just be a remnant of my development database, but I had
series entries with no patches.

I think part #1 is *required*. I'm not totally sure about #2, but it
seems safe.

Signed-off-by: Andy Doan <andy.doan@linaro.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
patchwork/migrations/0016_series_project.py

index befd6953f885e9c0f6013eb6bc0b6b3292b021a5..c4874f9733066593cdf46ed94a634f0c5694c715 100644 (file)
@@ -16,8 +16,10 @@ def forward(apps, schema_editor):
             series.project = series.cover_letter.project
             series.save()
         elif series.patches:
-            series.project = series.patches.first().project
-            series.save()
+            patch = series.patches.first()
+            if patch:
+                series.project = patch.project
+                series.save()
         else:
             # a series without patches or cover letters should not exist.
             # Delete it.
@@ -38,7 +40,7 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='series',
             name='project',
-            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='series', to='patchwork.Project'),
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='series', to='patchwork.Project'),
         ),
         migrations.RunPython(forward, reverse),
         migrations.AlterField(