0

I was wondering whether there is a way in marshmallow to have a field to be required depending on another value.

Eg:

{ 'name':'Tom' }

{ 'name':'Arthur', 'job':'teacher' }

I'd like to know if there is a way to make the field job required if isWorking=True (isWorking is not a field in the schema)

codeplay_
  • 31
  • 5

1 Answers1

0

You may use a schema validator with marshmallow.decorators.validates_schema.

If you set pass_original=True, you'll get input data in which you'll find isWorking. Then you can raise a ValidationError if job is missing.

Jérôme
  • 13,328
  • 7
  • 56
  • 106