1

I know that according to the Cerberus documentation, it is possible to define validation dependencies, according to other keys values, such as:

schema = {'field1': {'required': False}, 
          'field2': {'required': True, 
                     'dependencies': {'field1': ['one', 'two']}}}

Where field2 is valid only if field1 exists and has value one or two.

I would like to know if there's a way of having a validation rule that is considered depending on the value of the key itself.

Something like: field2 needs field1 value False only if field2 value is True, and vice-versa.

Only one of the fields must be allowed to be True at a time.

funky-future
  • 3,716
  • 1
  • 30
  • 43
gcw
  • 1,639
  • 1
  • 18
  • 37

1 Answers1

3

This could probably be solved by using dependencies in conjunction with oneof (docs) rule.

However, there's currently an issue which might prevent this solution from working (ticket). Unfortunately I don't have the time to triage this right now, but you could give it a shot and report back here and, eventually, on the ticket itself. Good luck!

Nicola Iarocci
  • 6,606
  • 1
  • 20
  • 33