]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
forms: Don't attempt to evaluate State at startup
authorStephen Finucane <stephen@that.guru>
Tue, 4 Sep 2018 10:03:00 +0000 (11:03 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 31 Aug 2019 11:17:09 +0000 (12:17 +0100)
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>
patchwork/forms.py

index 5d4c920a80cdce6ca8b0da10319e2722aefd861e..5690eb011b4a6652ca6100ffafb672e440d5a97b 100644 (file)
@@ -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