Validate the relationship between fields with Marshmallow’s @validates_schema
decorator
When unverified data enters in your app, you can validate it by defining a Marshmallow schema like this:
Then, verify fields with complex requirements using @validates
(docs):
And confirm important relationships between fields with @validates_schema
(docs):1
You can include as many instances of @validates
and @validates_schema
as you like. Or just stuff everything in one big @validates_schema
method. Your call.
Footnotes
-
When using
@validates_schema
, it’s important to include**kwargs
in your decorated method’s signature to avoid aTypeError
saying<method name> got an unexpected keyword argument 'partial'
. Per Marshmallow’s docs,partial
andmany
are always passed as keyword arguments to the decorated method. ↩