From 29418b943351c94fe9f1ad8de868591318551e48 Mon Sep 17 00:00:00 2001 From: Oskari Lehto Date: Tue, 29 Aug 2017 10:23:26 +0300 Subject: [PATCH] Fix GroupedQuerySelectMultipleField validator Refs #121 --- tests/test_query_select_field.py | 1 + wtforms_alchemy/fields.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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())