Skip to content
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
Closed

Normalization not working for valueschema and propertyschema #155

dkellner opened this issue Sep 29, 2015 · 2 comments

Comments

@dkellner
Copy link
Contributor

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
Copy link
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.

@dkellner
Copy link
Contributor Author

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
- '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
- '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 pushed a commit that referenced this issue Oct 19, 2015
- '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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants