]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Resolve issues with Patch.state
authorStephen Finucane <stephen.finucane@intel.com>
Wed, 22 Jul 2015 08:34:58 +0000 (09:34 +0100)
committerStephen Finucane <stephen.finucane@intel.com>
Fri, 16 Oct 2015 22:20:08 +0000 (23:20 +0100)
The initial migration introduced in '30bb271' was incomplete: running
'makemigrations' on the current codebase will produce a migration which
could not be applied cleanly. The reason for this was the non-loading
of initial data for the 'State' model.

Fix this issue by only referencing the contents of the 'State' model
when we have to (on save of a 'Patch' object), thus allowing the user
suitable time to apply this initial data.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
Acked-by: Damien Lespiau <damien.lespiau@intel.com>
patchwork/migrations/0001_initial.py
patchwork/migrations/0002_fix_patch_state_default_values.py [new file with mode: 0644]
patchwork/models.py

index 65d1c35564143b290a1839d7e15dde5d062cb083..812558a24ff368d664c62084a9c8abedf27b64e0 100644 (file)
@@ -2,12 +2,12 @@
 from __future__ import unicode_literals
 
 from django.db import models, migrations
-from django.core.management import call_command
 import datetime
 import patchwork.models
 import django.db.models.deletion
 from django.conf import settings
 
+
 class Migration(migrations.Migration):
 
     dependencies = [
diff --git a/patchwork/migrations/0002_fix_patch_state_default_values.py b/patchwork/migrations/0002_fix_patch_state_default_values.py
new file mode 100644 (file)
index 0000000..4887935
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='patch',
+            name='state',
+            field=models.ForeignKey(to='patchwork.State', null=True),
+        ),
+    ]
index c2b8a9c9408d8cfe0d986d1aafd54f23dd0beb0b..0c8022cf8b7930754b5f809046f942686b4fd810 100644 (file)
@@ -243,7 +243,7 @@ class Patch(models.Model):
     date = models.DateTimeField(default=datetime.datetime.now)
     submitter = models.ForeignKey(Person)
     delegate = models.ForeignKey(User, blank = True, null = True)
-    state = models.ForeignKey(State, default=get_default_initial_patch_state)
+    state = models.ForeignKey(State, null=True)
     archived = models.BooleanField(default = False)
     headers = models.TextField(blank = True)
     content = models.TextField(null = True, blank = True)
@@ -279,10 +279,8 @@ class Patch(models.Model):
             self._set_tag(tag, counter[tag])
 
     def save(self):
-        try:
-            s = self.state
-        except:
-            self.state = State.objects.get(ordering =  0)
+        if not hasattr(self, 'state') or not self.state:
+            self.state = get_default_initial_patch_state()
 
         if self.hash is None and self.content is not None:
             self.hash = hash_patch(self.content).hexdigest()