New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalization not working for valueschema and propertyschema #155

Closed
dkellner opened this Issue Sep 29, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@dkellner
Copy link
Contributor

dkellner commented Sep 29, 2015

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.

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Sep 29, 2015

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.

@dkellner

This comment has been minimized.

Copy link
Contributor

dkellner commented Oct 1, 2015

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

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Oct 16, 2015

Fixes for normalization of subdocuments
- 'allow_unknown' and 'purge_unknown' are always considered
- normlization of mapping-keys from rules in 'propertyschema'
- normlization of mapping-keys from rules in 'valueschema'

adresses pyeve#155

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Oct 16, 2015

Fixes for normalization of subdocuments
- 'allow_unknown' and 'purge_unknown' are always considered
- normlization of mapping-keys from rules in 'propertyschema'
- normlization of mapping-values from rules in 'valueschema'

adresses pyeve#155

nicolaiarocci added a commit that referenced this issue Oct 19, 2015

Fixes for normalization of subdocuments
- 'allow_unknown' and 'purge_unknown' are always considered
- normlization of mapping-keys from rules in 'propertyschema'
- normlization of mapping-values from rules in 'valueschema'

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