Comments (4)
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.
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.
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.
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)
- Should forms be validated without request data? HOT 2
- Incorrect docstring? HOT 9
- ValueError: not enough values to unpack (expected 4, got 3) HOT 1
- IntegerFiled property can not pass the InputRequired or DataRequired validator when it is 0 HOT 1
- SelectMultipleField overrides default, keyword and obj provided values when empty post data is provided to the form HOT 4
- SelectMultipleField should support choices specified as coercible values. HOT 2
- Question: Is it possible to create a dynamic/adaptive forms with WTForms? HOT 1
- Missing period for two messages HOT 1
- tlhlh HOT 1
- Form field errors not JSON serializable with default Flask JSONProvider HOT 3
- Warn when using obsolete DateTime field
- Allow invalid value error message to be customised
- Would you consider adding timezone management to DateTimeField?
- Cannot update field data on numeric fields when formdata is processed HOT 1
- Optional doesn't support multivalued fields HOT 1
- SelectField / RadioField should have translated options HOT 1
- Support for async validation mechanisms
- Flask, Sqlalchemy app crashes with namespace collision on native Python datetime module. HOT 1
- URL validator has incorrect regexp range for scheme
- Optional doesn't check field.data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wtforms.