Unable to use validators with PatchJSONParameters
See original GitHub issueI am not able to use the validates
decorator using PatchJSONParameters
.
For example, using the following code raise a ValueError
(field does not exist) while there are fields in PATH_CHOICES
.
@validates('name')
def validate_name(self, data):
if len(data)<3:
raise ValidationError('Too short!')
I am not even sure that this is an issue as I don’t know how I am supposed to do it. I can see there is already some code to map validators with patched fields in PatchJSONParameters.__init__
:
self.fields['op'].validators = \
self.fields['op'].validators + [validate.OneOf(self.OPERATION_CHOICES)]
self.fields['path'].validators = \
self.fields['path'].validators + [validate.OneOf(self.PATH_CHOICES)]
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
PATCH with ValidateModelState enabled and [Required ...
If I provide ValidateModelState =true, then every PATCH failed on validation on properties with [Required] attribute.
Read more >Unable to patch data to FormArray - Stack Overflow
Take care when patching array. Because patchValue of FormArray patches values by the index: patchValue(value: any[], options: {onlySelf?:
Read more >Resolve the "Parameter validation failed" error in AWS ...
How do I resolve the "Parameter validation failed: parameter value 'abc' for parameter name 'ABC' does not exist" error in CloudFormation?
Read more >Validation with Hibernate Validator - Quarkus
This guide covers how to use Hibernate Validator/Bean Validation for: ... The method parameter ( book ) is created from the JSON payload...
Read more >JSON Patch | jsonpatch.com
JSON Patch is a format for describing changes to a JSON document. It can be used to avoid sending a whole document when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you @frol for your support and detailed answers. 😃 You should get paid for this! The article from William Durand is indeed excellent reading. I think that the workaround is good enough.
I wish that your patches (especially marshmallow integration) will be merged into Flask-RESTPlus one day.
@DurandA Please, read this short article on the PATCH matter: http://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/. After you read it, you should understand that the classes inherited from
PatchJSONParameters
have only 3 (three) constant fields:op
,path
, andvalue
. Thus, there won’t be anyname
field. You may try to use@validates_schema
(it should work in theory, but I haven’t tried it myself):NOTE: This is just a workaround since there must be a nicer way to implement this.