You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to the patch provided in #605SelectMultipleField.pre_validate() behaves unexpectedly, the method wasn't updated to support a value only list as choices.
pre_validate expects choices to be a list of (value, label) tuples thus validating the choices by doing:
values=list(c[0] forcinself.choices)
fordinself.data:
ifdnotinvalues:
raiseValidationError(
self.gettext("'%(value)s' is not a valid choice for this field")
%dict(value=d)
)
however this means that if choices is a value only list, such as ['foo', 'bar'], c[0] in self.choices checks for the first char of the element (c[0]='f', c[0]='b') breaking the validation.
A possible fix could be reusing the checks used in iter_choices:
however I personally suggest that formatting choices at __init__ would be a better option, it would stop these issues and make things more consistent. The main issue is that at the moment every method that uses choices has to check for its format, might as well define it a the top and be done with it.
The text was updated successfully, but these errors were encountered:
Due to the patch provided in #605
SelectMultipleField.pre_validate()
behaves unexpectedly, the method wasn't updated to support a value only list aschoices
.pre_validate
expectschoices
to be a list of(value, label)
tuples thus validating the choices by doing:however this means that if
choices
is a value only list, such as['foo', 'bar']
,c[0] in self.choices
checks for the first char of the element (c[0]='f', c[0]='b'
) breaking the validation.A possible fix could be reusing the checks used in
iter_choices
:however I personally suggest that formatting
choices
at__init__
would be a better option, it would stop these issues and make things more consistent. The main issue is that at the moment every method that useschoices
has to check for its format, might as well define it a the top and be done with it.The text was updated successfully, but these errors were encountered: