Yesterday Cerberus 0.8.1 was released with a few little fixes, one of them being more a new feature than a fix really: sub-document fields can now be set as field dependencies by using a ‘dotted’ notation.

So, suppose we set the following validation schema:

schema = {
  'test_field': {
    'dependencies': [
      'a_dict.foo', 
      'a_dict.bar'
    ]
  },
  'a_dict': {
    'type': 'dict',
      'schema': {
        'foo': {'type': 'string'},
        'bar': {'type': 'string'}
      }
  }
}

Then, we can validate a document like this:

>>> v = Validator(schema)
>>> document = {
      'test_field': 'foobar', 
      'a_dict': {'foo': 'foo'}
    }

>>> v.validate(document, schema)
False

>>> v.errors
{'test_field': "field 'a_dict.bar' is required"}

This release will not work with Eve 0.5.2 or less so if you want to use Cerberus 0.8.1 with Eve make sure you upgrade to Eve 0.5.3, released today. By the way, yesterday we hit 2K stargazers and 70 contributors on the Eve repository, quite the milestone!

If you want to get in touch, I am @nicolaiarocci on Twitter.