Skip to content

Commit

Permalink
Skips *of-rules for valid None values
Browse files Browse the repository at this point in the history
Closes #582.
  • Loading branch information
funkyfuture committed Jul 23, 2023
1 parent 4ae57ef commit 35d9f7b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cerberus/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ def test_nullable_skips_allowed():
assert_success({'role': None}, schema)


@mark.parametrize("rule", ("all", "any", "none", "one"))
def test_nullable_skips_of_roles(rule):
assert_success(
schema={
"foo": {
"type": "dict",
"nullable": True,
rule + "of_schema": [{"bar": {"type": "string"}}],
}
},
document={"foo": None},
)


def test_readonly_field():
field = 'a_readonly_string'
assert_fail(
Expand Down
4 changes: 4 additions & 0 deletions cerberus/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,9 @@ def _validate_nullable(self, nullable, field, value):
if not nullable:
self._error(field, errors.NOT_NULLABLE)
self._drop_remaining_rules(
"allof",
'allowed',
"anyof",
'empty',
'forbidden',
'items',
Expand All @@ -1383,6 +1385,8 @@ def _validate_nullable(self, nullable, field, value):
'max',
'minlength',
'maxlength',
"noneof",
"oneof",
'regex',
'schema',
'type',
Expand Down

0 comments on commit 35d9f7b

Please sign in to comment.