Skip to content

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

@CD3

Description

@CD3

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions