Skip to content

Cannot import _legacy_validators #131

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

Closed
rochacbruno opened this issue Sep 20, 2023 · 5 comments · Fixed by #132
Closed

Cannot import _legacy_validators #131

rochacbruno opened this issue Sep 20, 2023 · 5 comments · Fixed by #132

Comments

@rochacbruno
Copy link

jsonschema released 2 hours ago comes with a change

2023-09-20_17-20

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_validators
@TheTeaCat
Copy link

TheTeaCat commented Sep 20, 2023

Facing the same issue right now. Was a result of the following commit which renamed _legacy_validators to _legacy_keywords: python-jsonschema/jsonschema@9313230

@rochacbruno
Copy link
Author

@TheTeaCat workaround for now is jsonschema<=4.19.0

jctanner pushed a commit to ansible/galaxy_ng that referenced this issue Sep 20, 2023
Cannot import _legacy_validators from JSONSchema
due to: python-openapi/openapi-schema-validator#131

No-Issue
@tucked
Copy link

tucked commented Sep 20, 2023

Is there a reason we need to access a private API here?

@p1c2u
Copy link
Collaborator

p1c2u commented Sep 20, 2023

Some OpenAPI schema keywords (such as anyOf, oneOf, allOf) are extended versions of Draft ones.

@Julian
Copy link

Julian commented Jan 4, 2024

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.

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 a pull request may close this issue.

5 participants