Skip to content

schema: unexpected handling of lists in records config #6

@MSusik

Description

@MSusik

Recently I encountered a problem with JSONAlchemy config (.cfg) files. I wanted to create a field which should be a list of strings inside the record. Here is the definition:

schema:
        {'emails': {'type': 'list', 'force': True, 'schema': {'type': 'string'}}}

When there is no key emails in the dictionary handled to Record.create method, I obtain:

>>> rec['emails']
[{'type': None}]

It seems that JSONAlchemy always understands schema as a base for a dictionary. Other than that, it works fine.

I can make it working by defining the field as:

schema:
        {'emails': {'type': 'list', 'force': True, 'items': {'type': 'string'}}}

But in this case I can't pass the validation, as Cerberus expects dictionaries inside the list.

https://cerberus.readthedocs.org/en/latest/#items-list
https://cerberus.readthedocs.org/en/latest/#schema-list
Please note that Cerberus' documentation is not complete.

What to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions