Skip to content

Email() validation failed should raise a StopValidation error #360

Open

Description

@protream

Look at this case:

class UserForm(FlaskForm):
    email = StringField('email', validators=[Email()])

    def validate_email(self, field):
        if not User.query.filter_by(email=email).first():
           raise ...

If input is not a email, validate_email will still be executed, which make no sense. So I think Email should raise a StopValidation error.

Activity

  1. whb07 commented on Jun 12, 2018

    @whb07
    Contributor

    Im not really clear as to what you're saying here. In this example assuming you enter a non valid email the email field will already have the error associated to it. At the validate_email method you can add a custom logic like check to see if the email might potentially be assigned already like in your example.

    Either way you would want to verify if the form itself can validate via form.validate().

  2. davidism commented on Jun 12, 2018

    @davidism
    Member

    See #61 for more discussion on inconsistency in validation.

  3. davidism commented on Jun 12, 2018

    @davidism
    Member

    Summary: there needs to be a comprehensive review about which validators should stop validation versus continue. Expecting that an invalid email address doesn't continue validation does make sense, it's not clear at first why validators should have to validate the data before validating the value.

  4. added this to the 4.0.0 milestone on May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions