diff --git a/tests/test_query_select_field.py b/tests/test_query_select_field.py index e2cc481..8496854 100644 --- a/tests/test_query_select_field.py +++ b/tests/test_query_select_field.py @@ -348,6 +348,7 @@ def test_multiple_values_without_query_factory(self): form = MyForm(DummyPostData(cities=['1', '666'])) form.cities.query = self.session.query(self.City) + assert not form.validate() assert [x.id for x in form.cities.data] == [1] assert not form.validate() form.populate_obj(obj) diff --git a/wtforms_alchemy/fields.py b/wtforms_alchemy/fields.py index 362a744..79488c6 100644 --- a/wtforms_alchemy/fields.py +++ b/wtforms_alchemy/fields.py @@ -568,7 +568,7 @@ def process_formdata(self, valuelist): self._formdata = set(valuelist) def pre_validate(self, form): - if self._invalid_formdata: + if self.data and self._invalid_formdata: raise ValidationError(self.gettext('Not a valid choice')) elif self.data: obj_list = list(x[1] for x in self._get_object_list())