Skip to content

Normalization not working for valueschema and propertyschema #155

Closed

Description

@dkellner

Hey there,

I just stumbled over the following issue: When using 'coerce' in valueschema or propertyschema, validator.document does not get updated accordingly. Consider the following (currently failing) tests:

    def test_coerce_in_valueschema(self):
        schema = {'thing': {'type': 'dict',
                            'valueschema': {'coerce': int}}}
        v = Validator(schema)
        self.assertEqual(v.validated({'thing': {'amount': '2'}})
                                     ['thing']['amount'], 2)  # noqa

    def test_coerce_in_propertyschema(self):
        schema = {'thing': {'type': 'dict',
                            'propertyschema': {'coerce': int}}}
        v = Validator(schema)
        self.assertEqual(v.validated({'thing': {'5': 'foo'}})
                                     ['thing'][5], 'foo')  # noqa

I don't know whether this is actually meaningful in case of propertyschema. For valueschema, normalization should be possible IMO.

Activity

  1. funkyfuture commented on Sep 29, 2015

    @funkyfuture
    Member

    that would work:

        schema = {'thing': {'type': 'dict',
                            'allow_unknown': {'coerce': int},
                            'schema': {}}}
    

    but i see that it's not straightforward.

    normalization of keys can be achieved with a 'rename_handler': int.

    to streamline both, the need to give an empty schema would have to be removed.

  2. dkellner commented on Oct 1, 2015

    @dkellner
    ContributorAuthor

    Thank you! This solves my problem for now :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions