]> git.ipfire.org Git - thirdparty/patchwork.git/commit
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)
commit8c3ed2b0c3d7f39a66e58a06bba5517b3cbdb4d6
tree9737742d37fa619ab9f319abd2700d22f4fc2a05
parentf94bb4eb3693d581c0658eba6ab4aa7723eca955
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>
patchwork/forms.py