1

I'm attempting to construct a recursive schema using cerberus but appear to be missing the point of how it should work. Could someone help me out?

In the documentation and old issues in the repo it is explained that the way to handle recursion is to use schema registries to create self-referencing schema, otherwise we hit recursion depth limits.

However, trying something very basic leads to a TypeError.

It would be great to get a schema recursion example in the docs please! I'd be happy to help submit one once I understand what is going on.

cerberus.schema_registry.add(
    'user_schema', 
    {
        'uid': {
            'type': 'integer'
        }, 
        'next': {
            'type': 'list',
            'schema': 'user_schema'
        }
    }
)

schema = {'sender': {'schema': 'user_schema'}}

v = cerberus.Validator(schema=schema)

v.validate({
    'sender': {
        'uid': 1,
        'next': [
            {
                'uid': 1,
            }
        ]
    }
})

Running the above leads to the following unhandled exception:

TypeError: argument of type 'NoneType' is not iterable

Help would be very much appreciated!

Sirrah
  • 1,681
  • 3
  • 21
  • 34
  • could you please share the line no where this is exactly happening? also NoneType mean NA or nan values ..... so you might have NA values in your output.... for that you have to put a IF condition first and else condition to put some default value... I hope this helps – Puneet Sinha Jan 22 '19 at 11:46

1 Answers1

1

Ok, moments after posting this I realised I just wrote my schema incorrectly. I am a dumb human.

cerberus.schema_registry.add(
'user_schema', 
{
    'uid': {
        'type': 'integer'
    }, 
    'next': {
        'type': 'list',
        'schema': {
            'type': 'dict',
            'schema': 'user_schema'
        }
    }
}
)

The above works. -_-

Sirrah
  • 1,681
  • 3
  • 21
  • 34