Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Python 3.10.12 - Cerberus v1.3.5 - validate error for - dict-->dict-->list - Is this possible to validate with Cerberus?

$
0
0

I need help to understand whether Cerberus v1.3.5 supports validation for the below YAML file. If yes, I would like to know what is wrong with schema I used below.

This YAML file is a test file which is part of the bigger YAML file.

In the YAML file, "myDictOne" and "myListOne" should be there and named like that (test names). All others are variables. Therefore, in the validation schema, both "myDictOne" and "myListOne" should be there.

With the schema that I have defined to validate this YAML file, it gives the error "There's no handler for 'abc' in the 'validate' domain".

Can someone please help with the correct "schema" to validate this test YAML file?

Schema used:

schema = { 'myDictOne': { 'type': 'dict', 'required': True, 'schema': {'myListOne' : { 'type': 'list', 'required': True, 'schema': { 'abc': {'type': 'string', 'required': True}, 'xyz': {'type': 'string', 'required': True} } }, 'myListTwo' : { 'type': 'list', 'required': True, 'schema': { 'abc': {'type': 'string', 'required': True}, 'xyz': {'type': 'string', 'required': True} } }               } } }

test-12-Apr.yaml file:

myDictOne:  myListOne:  - abc:    - abcentry11    - abcentry12    xyz:    - xyzentry11    - xyzentry12  - abc:    - abcentry13    xyz:    - xyzentry13  - abc:    - abcentry14    xyz:    - xyzentry14  myListTwo:  - abc:    - abcentry21    - abcentry22    xyz:    - xyzentry21    - xyzentry22  - abc:    - abcentry23    xyz:    - xyzentry23  - abc:    - abcentry24    xyz:    - xyzentry24

What and How I tried to test this validations:

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import yaml>>> from cerberus import Validator>>> with open("test-12-Apr.yaml", 'r') as file:...     myData = yaml.safe_load(file)...>>> myData{'myDictOne': {'myListOne': [{'abc': ['abcentry11', 'abcentry12'], 'xyz': ['xyzentry11', 'xyzentry12']}, {'abc': ['abcentry13'], 'xyz': ['xyzentry13']}, {'abc': ['abcentry14'], 'xyz': ['xyzentry14']}], 'myListTwo': [{'abc': ['abcentry21', 'abcentry22'], 'xyz': ['xyzentry21', 'xyzentry22']}, {'abc': ['abcentry23'], 'xyz': ['xyzentry23']}, {'abc': ['abcentry24'], 'xyz': ['xyzentry24']}]}}>>>>>> schema = { 'myDictOne': { 'type': 'dict', 'required': True, 'schema': {...                'myListOne' : { 'type': 'list', 'required': True, 'schema': { 'abc': {'type': 'string', 'required': True}, 'xyz': {'type': 'string', 'required': True} } },...                'myListTwo' : { 'type': 'list', 'required': True, 'schema': { 'abc': {'type': 'string', 'required': True}, 'xyz': {'type': 'string', 'required': True} } }...                } } }>>>>>> v = Validator(schema)>>> v.validate(myData)Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1040, in validate    self.__validate_definitions(definitions, field)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1110, in __validate_definitions    result = validate_rule(rule)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1085, in validate_rule    return validator(definitions.get(rule, None), field, value)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1491, in _validate_schema    self.__validate_schema_mapping(field, schema, value)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1504, in __validate_schema_mapping    if not validator(value, update=self.update, normalize=False):  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1040, in validate    self.__validate_definitions(definitions, field)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1110, in __validate_definitions    result = validate_rule(rule)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1085, in validate_rule    return validator(definitions.get(rule, None), field, value)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1489, in _validate_schema    self.__validate_schema_sequence(field, schema, value)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1518, in __validate_schema_sequence    validator(  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1040, in validate    self.__validate_definitions(definitions, field)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1110, in __validate_definitions    result = validate_rule(rule)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 1084, in validate_rule    validator = self.__get_rule_handler('validate', rule)  File "/usr/local/lib/python3.10/dist-packages/cerberus/validator.py", line 366, in __get_rule_handler    raise RuntimeError(RuntimeError: There's no handler for 'abc' in the 'validate' domain.>>>

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>