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

Fix #379: Regression with Any and required #380

Merged
merged 1 commit into from
Jan 13, 2019
Merged

Fix #379: Regression with Any and required #380

merged 1 commit into from
Jan 13, 2019

Conversation

CedricCabessa
Copy link
Contributor

In 0.9.3, the Schemas associated to the Any validators where setup with the
required argument given to Any

https://github.com/alecthomas/voluptuous/blob/0.9.3/voluptuous/validators.py#L218

This allow us to write something like:

Schema(Any({'a': int}, {'b': str}, required=True))

In recent version, the required keyword is ignored.

This patch pass the required argument to the Schemas associated with the
SubValidator.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 95.396% when pulling cf3e2dc on CedricCabessa:fix-379-regression-with-Any-and-required into 7e18e1c on alecthomas:master.

@coveralls
Copy link

coveralls commented Jan 9, 2019

Coverage Status

Coverage increased (+0.02%) to 95.404% when pulling 7b4efb4 on CedricCabessa:fix-379-regression-with-Any-and-required into 7e18e1c on alecthomas:master.

@alecthomas
Copy link
Owner

Aaah, nice find. Thank you for the PR. Just one minor change and I'm happy to merge.

@CedricCabessa
Copy link
Contributor Author

I just amend my commit with your remark. Thanks

However, I just found out that some case do not work :-(

like "dict in dict", the empty dict is considered valid but should not

schema = Schema(Any({'a': Any(float, int)},
                         {'b': int},
                         {'c' : {'aa': int}},
                         required=True))

If it's ok, I'll try to come back to you with another commit on this branch to fix that.
Or you can merge this and I'll open another PR, as you prefer

@CedricCabessa
Copy link
Contributor Author

Here is the 2nd part of the patch to allow "recursive schema"
Let me know what you think :-)

In 0.9.3, the `Schema`s associated to the `Any` validators where setup with the
`required` argument given to `Any`

https://github.com/alecthomas/voluptuous/blob/0.9.3/voluptuous/validators.py#L218

This allow us to write something like:

```
Schema(Any({'a': int}, {'b': str}, required=True))
```

In recent version, the `required` keyword is ignored.

This patch pass the required argument to the `Schema`s associated with the
`SubValidator`.
]
self._compiled = []
for v in self.validators:
schema.required = self.required
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still a leftover? Should this be v.required = self.required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is correct. Test fail otherwise

Also note that the line must be inside the loop. I'm not totally clear on what happen... but tests are passing ...

@alecthomas alecthomas merged commit 806d1c5 into alecthomas:master Jan 13, 2019
@alecthomas
Copy link
Owner

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants