aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen.finucane@intel.com>2015-07-22 09:34:58 +0100
committerStephen Finucane <stephen.finucane@intel.com>2015-10-16 23:20:08 +0100
commitd6e7b50b3f70f908d51feca596cd761545910972 (patch)
tree9f46977400009fdb967501ee7f2fbe132b4810c2
parent634d97275f152470973996c242c9668bb53dff9f (diff)
downloadpatchwork-d6e7b50b3f70f908d51feca596cd761545910972.tar
patchwork-d6e7b50b3f70f908d51feca596cd761545910972.tar.gz
models: Resolve issues with Patch.state
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>
-rw-r--r--patchwork/migrations/0001_initial.py2
-rw-r--r--patchwork/migrations/0002_fix_patch_state_default_values.py19
-rw-r--r--patchwork/models.py8
3 files changed, 23 insertions, 6 deletions
diff --git a/patchwork/migrations/0001_initial.py b/patchwork/migrations/0001_initial.py
index 65d1c35..812558a 100644
--- a/patchwork/migrations/0001_initial.py
+++ b/patchwork/migrations/0001_initial.py
@@ -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
index 0000000..4887935
--- /dev/null
+++ b/patchwork/migrations/0002_fix_patch_state_default_values.py
@@ -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),
+ ),
+ ]
diff --git a/patchwork/models.py b/patchwork/models.py
index c2b8a9c..0c8022c 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -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()