Skip to content

fixed SelectMultipleField none_of validator - #538

Closed
AbdullahAlajmi wants to merge 1 commit into
pallets-eco:masterfrom
AbdullahAlajmi:fix_SelectMultipleField_noneof
Closed

AbdullahAlajmi wants to merge 1 commit into
pallets-eco:masterfrom
AbdullahAlajmi:fix_SelectMultipleField_noneof

Conversation

@AbdullahAlajmi

Copy link
Copy Markdown

none_of validator for SelectMultipleField is always true and will never raise a ValidationError.
none_of validator now supports both SelectField and SelectMultipleField.

@ftm

ftm commented Mar 31, 2020

Copy link
Copy Markdown
Contributor

The CI is failing due to the issues fixed in #541. If you rebase your branch off of the current master you should receive all the necessary changes.

@ftm ftm added waiting onhold Waiting feedback and removed waiting labels Mar 31, 2020
@azmeuk

azmeuk commented Apr 21, 2020

Copy link
Copy Markdown
Member

Also, can you please add some unit tests to this PR?

Comment thread src/wtforms/validators.py
self.values_formatter = values_formatter

def __call__(self, form, field):
if field.type == "SelectMultipleField":

@davidism davidism Apr 21, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be the solution, as it excludes any other fields that have a list of data. And it just doesn't feel very good to check the name of a specific field like this.

Could maybe do if isinstance(field.data, list). That might have issues with FieldList, but that might not matter. Would also have issues if you want to check "none of these specific sets of choices", rather than "doesn't contain any of these choices".

Comment thread src/wtforms/validators.py
message % dict(values=self.values_formatter(self.values))
)

if field.data in self.values:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the field is SelectMultipleField, this behavior still triggers if the new if block doesn't raise. That would sort of address my point about validating lists vs items, but it doesn't seem like the right design because there's still no way to control which type of validation you intended.

@azmeuk

azmeuk commented Oct 10, 2023

Copy link
Copy Markdown
Member

Closing as inactive, and replaced by #807

@azmeuk azmeuk closed this Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

onhold Waiting feedback

Development

Successfully merging this pull request may close these issues.

4 participants