summaryrefslogtreecommitdiff
path: root/patchwork/forms.py
diff options
context:
space:
mode:
authorDaniel Axtens <dja@axtens.net>2016-08-09 14:27:36 +1000
committerStephen Finucane <stephenfinucane@hotmail.com>2016-08-20 19:18:20 +0100
commit231966452f22dd344eabdd4f0722ce5463d1469a (patch)
treef00b68f2eb1b99d49fe1577625b757c5d7469b13 /patchwork/forms.py
parentab5eb273f00a90bad035f6189b8fff7ac4d07fbf (diff)
downloadpatchwork-231966452f22dd344eabdd4f0722ce5463d1469a.tar
patchwork-231966452f22dd344eabdd4f0722ce5463d1469a.tar.gz
Fix failure to start with uninitalised database
An OptionalModelChoiceField will attempt to query the database to get choices in its __init__ method. This fails if the database hasn't been initialised yet. So, put that in a try/catch block. This lets things work through the migration and loading of data from fixtures. Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Reviewed-by: Stephen Finucane <stephenfinucane@hotmail.com>
Diffstat (limited to 'patchwork/forms.py')
-rw-r--r--patchwork/forms.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/patchwork/forms.py b/patchwork/forms.py
index 3f876b7..1897093 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -21,6 +21,7 @@ from __future__ import absolute_import
from django.contrib.auth.models import User
from django import forms
+from django.db.utils import ProgrammingError
from patchwork.models import Patch, State, Bundle, UserProfile
@@ -165,8 +166,14 @@ class OptionalModelChoiceField(forms.ModelChoiceField):
__init__(initial=self.no_change_choice[0], *args, **kwargs)
def _get_choices(self):
- choices = list(
- super(OptionalModelChoiceField, self)._get_choices())
+ # _get_choices queries the database, which can fail if the db
+ # hasn't been initialised yet. catch that and give an empty
+ # set of choices for now.
+ try:
+ choices = list(
+ super(OptionalModelChoiceField, self)._get_choices())
+ except ProgrammingError:
+ choices = []
choices.append(self.no_change_choice)
return choices