Git Product home page Git Product logo

Comments (4)

crast avatar crast commented on May 11, 2024

The reason that StopValidation isn't honored in process_formdata is that at this point, you're not actually validating, you're in Form.process() which calls Field.process().

The validation always starts when you call Form.validate(), regardless of whether there were processing errors (and those are stored in field.process_errors).

While I could see a reason for potentially setting a flag which stops validation from happening due to process errors, I can also see how it would limit the capabilities of validators to actually influence or be influenced by processing errors.

from wtforms.

davidism avatar davidism commented on May 11, 2024

at this point, you're not actually validating

Why is ValidationError handled at this point then? Why have a way to essentially pre-validate without being able to "pre-stop".

I understand from your explanation that a validator could check if field.process_errors is empty or data is not None before continuing. This should probably be added to the documentation on writing custom or in-line validators.

It's not even mentioned that the built-in validators do this check (data is not None). Looking at the source, some of them seem to think None means don't validate, while others assume a default value. And they all check and default in a different way. Not consistent.

I can't think of a situation where you would want to validate data that didn't even process correctly, so this just seems like unnecessary boilerplate, especially in-line validators that should be quick and easy to write.

Ultimately, it's not that big a deal, as I've managed to work around it and understand why it works the way it does. I just feel like this is all a little unclear and could be handled better.

from wtforms.

crast avatar crast commented on May 11, 2024

I concur.

In an attempt to add the features we wanted to ad without creating major API breakage, we haven't actually changed the paradigm yet in WTForms 2.0. WTForms 2.0 (released today) is a transition version, allowing a peek of some of the new design ideas while still having the Field contract be mostly unchanged. We're going to go stomping around now in our fields and breaking stuff for the next major release, but this allowed us to significantly reduce our code liability (we deprecated a lot of things, so that the next release will clearly be a breaking release as far as this is concerned.)

from wtforms.

crast avatar crast commented on May 11, 2024

Why is ValidationError handled at this point then? Why have a way to essentially pre-validate without being able to "pre-stop".

ValidationError specifically isn't handled, it's ValueError which is handled, of which ValidationError is a subclass. This is to catch any process-time errors that would have occurred during coercion, and they are kept on .process_errors of the field. By default, the validation adds the process errors to the errors.

from wtforms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.