Skip to content

Commit

Permalink
Fix: Allowed rule is not evaluated for fields w/ a None value
Browse files Browse the repository at this point in the history
Closes #454
  • Loading branch information
funkyfuture committed Jan 27, 2019
1 parent c4b069d commit 74caea6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Fixed
- Defaults are applied to undefined fields from an ``allow_unknown``
definition (`#310`_)
- The ``forbidden`` value now handles any input type (`#449`_)
- The `allowed` rule will not be evaluated on fields that have a legit ``None``
value (`#454`_)

Improved
~~~~~~~~
Expand Down Expand Up @@ -62,6 +64,7 @@ Docs
- Add a few clarifications to the GitHub issue template
- Update README link; make it point to the new PyPI website

.. _`#454`: https://github.com/pyeve/cerberus/pull/454
.. _`#451`: https://github.com/pyeve/cerberus/pull/451
.. _`#449`: https://github.com/pyeve/cerberus/pull/449
.. _`#435`: https://github.com/pyeve/cerberus/pull/435
Expand Down
5 changes: 5 additions & 0 deletions cerberus/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def test_nullable_field():
assert_fail({'a_not_nullable_field_without_type': None})


def test_nullable_skips_allowed():
schema = {'role': {'allowed': ['agent', 'client', 'supplier'], 'nullable': True}}
assert_success({'role': None}, schema)


def test_readonly_field():
field = 'a_readonly_string'
assert_fail(
Expand Down
1 change: 1 addition & 0 deletions cerberus/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,7 @@ def _validate_nullable(self, nullable, field, value):
if not nullable:
self._error(field, errors.NOT_NULLABLE)
self._drop_remaining_rules(
'allowed',
'empty',
'forbidden',
'items',
Expand Down

0 comments on commit 74caea6

Please sign in to comment.