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

NewValidator created after descend does not use extended validators from parent #1283

Closed
gobater opened this issue Jul 9, 2024 · 1 comment

Comments

@gobater
Copy link

gobater commented Jul 9, 2024

I have created a custom validator, Extending Draft7Validator to set defaults following the example in https://python-jsonschema.readthedocs.io/en/stable/faq/#why-doesn-t-my-schema-s-default-property-set-the-default-on-my-instance

    def _extend_validator_with_defaults(self, validator_class):
        original_validator = validator_class.VALIDATORS["properties"]

        def _properties_set_defaults(validator, properties, instance, schema):
            # set the defaults before anything else. Then we will validate also the defaults
            for property, subschema in properties.items():
                if "default" in subschema:
                    instance.setdefault(property, subschema["default"])

                if property in instance:
                    yield from validator.descend(
                        instance[property],
                        subschema,
                        path=property,
                        schema_path=property,
                    )

            yield from original_validator(validator, properties, instance, schema)

        return validators.extend(validator_class, {
            "properties": _properties_set_defaults,
        })

As soon as I descend into a reference (which contains a subschema), the custom validator is not called anymore.

@Julian
Copy link
Member

Julian commented Jul 10, 2024

Hi there, this seems likely to be a duplicate of #994.

@Julian Julian closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
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