Skip to content

Strange error message if length of list is wrong #505

@pravindahal

Description

@pravindahal

Used Cerberus version / latest commit: 1.3.1

  • I have the capacity to improve the docs when my problem is solved.

  • My question does not concern a practical use-case that I can't figure out
    to solve.

  • I have the capacity to submit a patch when a bug is identified.


Use-case abstract

Using list validator with incorrect number of items.


Bug report / Feature request

#!/usr/bin/env python2

from cerberus import Validator
import json

SCHEMA = {
    'test_list': {
        'type': 'list',
        'required': True,
        'items': [
            {
                'type': 'string',
            },
            {
                'type': 'string',
            }
        ]
    }
}

payload = {
    'test_list': [
        'test'
    ]
}

validator = Validator(SCHEMA)
validator.validate(payload)
print json.dumps(validator.errors)

Expected output:

{
	"test_list": ["length of list should be 2, it is 1"]
}

Actual output:

{
	"test_list": ["length of list should be [{'type': 'string'}, {'type': 'string'}], it is 2"]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions