-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate after setting multiple fields at once #72
Comments
This is a great suggestion ! It seems to connect with similar ideas/suggestions #8 and #25 I do not remember if I already wrote something in the code to prepare this, I'll need to investigate. Anyway a context manager would seem quite appropriate to disable validation temporarily and set it back on exit: with validate_once(t):
t.a = 100
t.b = 50 Maybe we could think about alternate names or additional complementary helpers, such as
What do you think ? |
I've just started looking at pyfields as an alternative to marshmallow, with the hopes of using it for convenient form and API parameter validation while providing a simple object with fields representing the submitted values. For me the ability to validate all values at once, providing a Flask form object (or some other dict) as input to my constructor, would be particularly helpful -- especially if I could get a marshmallow-like error result out of the process, mapping fieldnames to lists of error messages for those fields that failed validation. Hope this makes sense... been learning a lot this afternoon. Thanks! |
Thanks @jgarbers for your feedback ! Your message does not really seem to relate to this issue #72 - @bharathbhushan1 meant validation that can not be performed field by field but once all fields have been set. So I would recommend that you open a new dedicated issue. To give a first level of answer, you can already validate all values at once by passing a Maybe this should be solved in a different function that we could generate optionally on the class ? or we could imagine a boolean flag triggering this in the constructor. Or maybe we could make this the default behaviour of the generated constructor ? I have no strong opinion here but performance might be something to consider. |
The requirement is to set multiple fields which have individual validators where there could be a period where the invariants are not satisfied but at the end of the "transaction", all validators are satisfied. Is there a way to get this done? If not, can we add this as an enhancement?
The text was updated successfully, but these errors were encountered: