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

Validator options not passed to "sub-schemas" #40

Closed
CD3 opened this issue May 30, 2014 · 2 comments
Closed

Validator options not passed to "sub-schemas" #40

CD3 opened this issue May 30, 2014 · 2 comments

Comments

@CD3
Copy link
Contributor

@CD3 CD3 commented May 30, 2014

To validate a nested dict I am using the "schema" rule to define the rules for each level of the dict. The schema rule creates a new Validator object with the schema defined by the rule and passes the corresponding value in the document to the validate function.

However, the options of the main Validator instance are not passed to these sub-Validator instances. So, if the "allow_unknown" attribute is set to true in the main Validator, it does not get set for all sub-Validators.

My idea would be to add a "set_parent" method to the Validator class that would set the "parent" attribute to some Validator instance and copy all setting attributes from it (so allow_uknown, ignore_none_values, etc would be copied).

I think the idea of Validators having parents would be useful in general because then custom validator rules could then access data from an arbitrary position in the main schema no matter how far down they were created. If the documents passed into validate function also knew about their parent, then you could write validation rules that check other fields in the document to decide if the current field is valid (which is what I ultimately want to do).

@nicolaiarocci
Copy link
Member

@nicolaiarocci nicolaiarocci commented Jun 3, 2014

hello, thanks for your suggestion. This implementation simply copies the current validator instead of instancing a fresh instance, so options get carried along. This avoid adding complexity like navigation the validators tree.

nicolaiarocci added a commit that referenced this issue Jun 3, 2014
@CD3
Copy link
Contributor Author

@CD3 CD3 commented Jun 3, 2014

Thanks, I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants