Cannot import _legacy_validators
rochacbruno opened this issue · 5 comments
jsonschema released 2 hours ago comes with a change
packages/openapi_schema_validator/validators.py:5: in <module>
from jsonschema import _legacy_validators
E ImportError: cannot import name '_legacy_validators' from 'jsonschema' (/tmp/gng_testing/lib64/python3.11/site-suggestion
Do a conditional import on validators.py
try:
from jsonschema import _legacy_validators
except ImportError:
from jsonschema import _legacy_keywords as _legacy_validatorsFacing the same issue right now. Was a result of the following commit which renamed _legacy_validators to _legacy_keywords: python-jsonschema/jsonschema@9313230
@TheTeaCat workaround for now is jsonschema<=4.19.0
Is there a reason we need to access a private API here?
Some OpenAPI schema keywords (such as anyOf, oneOf, allOf) are extended versions of Draft ones.
Some OpenAPI schema keywords (such as anyOf, oneOf, allOf) are extended versions of Draft ones.
I've just noticed both the private usage and this issue -- there's no reason to use private APIs even if this is the case. There's perfectly public APIs for doing this, it's e.g. Draft202012Validator.VALIDATORS["anyOf"] etc., which get you the JSON Schema Draft 2020-12 implementation of that keyword. That's documented in the note for jsonschema.validators.extend though let me know if there's an even more obvious place you would have looked, as documentation is always lacking.
And please always raise such things even if there were missing APIs -- private indeed means private and can change at any time.
