You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're using forms for handling patch requests, you have to use validators.Optional() at the end of your validation chain for all fields.
That said, the test that validators.Optional() uses to determine if a field is blank is different than the test that patch_data uses. Entering white space for a field will match validators.Optional(), so validations will be skipped, but the resulting patch_dict will contain the field still.
The argument against this is that people should be able to set fields to null or blank via patch, but in that case wtforms-json could check the field's optional flag, yea?
For my use case, I'm using a custom validator in place of validators.Optional that doesn't consider ' ' falsy.
The text was updated successfully, but these errors were encountered:
Possible fix would be to monkey-patch validators.Optional to NOT stop validating when the field is blank. That way you could use validators.Optional with validators.DataRequired. When the field is blank, the DataRequired validator raises an error if it was used. When the field is missing, the Optional validator stops validating like normal and patch_data will NOT include that field.
If you're using forms for handling patch requests, you have to use
validators.Optional()
at the end of your validation chain for all fields.That said, the test that
validators.Optional()
uses to determine if a field is blank is different than the test thatpatch_data
uses. Entering white space for a field will matchvalidators.Optional()
, so validations will be skipped, but the resultingpatch_dict
will contain the field still.For example:
The argument against this is that people should be able to set fields to null or blank via patch, but in that case wtforms-json could check the field's
optional
flag, yea?For my use case, I'm using a custom validator in place of
validators.Optional
that doesn't consider' '
falsy.The text was updated successfully, but these errors were encountered: