aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2018-09-04 11:03:00 +0100
committerStephen Finucane <stephen@that.guru>2019-08-31 12:17:09 +0100
commit8c3ed2b0c3d7f39a66e58a06bba5517b3cbdb4d6 (patch)
tree9737742d37fa619ab9f319abd2700d22f4fc2a05
parentf94bb4eb3693d581c0658eba6ab4aa7723eca955 (diff)
downloadpatchwork-8c3ed2b0c3d7f39a66e58a06bba5517b3cbdb4d6.tar
patchwork-8c3ed2b0c3d7f39a66e58a06bba5517b3cbdb4d6.tar.gz
forms: Don't attempt to evaluate State at startup
As was designed, starting the interpreter would cause the State model and its entries to be evaluated. This was an issue if, for example, the model had been modified and you were attempting to apply the migration. Traceback (most recent call last): File "manage.py", line 11, in <module> execute_from_command_line(sys.argv) ... File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py", line 1199, in _set_queryset self.widget.choices = self.choices File "/home/patchwork/patchwork/patchwork/forms.py", line 157, in _get_choices super(OptionalModelChoiceField, self)._get_choices()) File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py", line 1143, in __len__ return (len(self.queryset) + (1 if self.field.empty_label is not None else 0)) File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 232, in __len__ self._fetch_all() File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1118, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 53, in __iter__ results = compiler.execute_sql(chunked_fetch=self.chunked_fetch) File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 899, in execute_sql raise original_exception django.db.utils.OperationalError: (1054, "Unknown column 'patchwork_state.slug' in 'field list'") Resolve this by moving the evaluation into '__init__', meaning it will only occur when a new form is created. Signed-off-by: Stephen Finucane <stephen@that.guru>
-rw-r--r--patchwork/forms.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/patchwork/forms.py b/patchwork/forms.py
index 5d4c920..5690eb0 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -165,7 +165,6 @@ class OptionalBooleanField(forms.TypedChoiceField):
class MultiplePatchForm(forms.Form):
action = 'update'
- state = OptionalModelChoiceField(queryset=State.objects.all())
archived = OptionalBooleanField(
choices=[('*', 'no change'), ('True', 'Archived'),
('False', 'Unarchived')],
@@ -176,6 +175,8 @@ class MultiplePatchForm(forms.Form):
super(MultiplePatchForm, self).__init__(*args, **kwargs)
self.fields['delegate'] = OptionalModelChoiceField(
queryset=_get_delegate_qs(project=project), required=False)
+ self.fields['state'] = OptionalModelChoiceField(
+ queryset=State.objects.all())
def save(self, instance, commit=True):
opts = instance.__class__._meta