dkellner · GitHub

Used Cerberus version / latest commit: current master ( 3f673c9 )

  • I consulted these documentations:

  • I consulted these sections of the docs (add more lines as necessary):

    • /api.html#rules-set-schema-registry
    • /normalization-rules.html
  • I found nothing relevant to my problem in the docs.

  • I found the documentation not helpful to my problem.

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

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


Bug report

Normalization rules like default cannot be part of a rules set. Consider these failings tests:

def test_rules_set_simple_with_default():
    rules_set_registry.add('foo', {'default': 42})
    assert_normalized({}, {'bar': 42}, {'bar': 'foo'})
def test_rules_set_simple_with_default_setter():
    rules_set_registry.add('foo', {'default_setter': lambda _: 42})
    assert_normalized({}, {'bar': 42}, {'bar': 'foo'})

The reason is - in my opinion - that the normalization code uses schema[field] directly without calling self._resolve_rules_set where appropriate. This causes other misbehaviour, too:

def test_rules_set_simple_with_none_value():
    rules_set_registry.add('foo', {'type': 'integer', 'nullable': True})
    assert_success({'bar': None}, {'bar': 'foo'})

This will fail because code in __normalize_default_fields will do schema['bar'].get('nullable', False) - which will fail because schema['bar'] will be the string 'foo'.

Is this actually a bug or am I missing something? Are rules sets just meant to be used for validation rules?

Read the original on github.com ↗