Skip to content

Cannot import _legacy_validators #131

Closed

Description

@rochacbruno

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

Activity

  1. TheTeaCat commented on Sep 20, 2023

    @TheTeaCat

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

  2. rochacbruno commented on Sep 20, 2023

    @rochacbruno
    Author

    @TheTeaCat workaround for now is jsonschema<=4.19.0

  3. added a commit that references this issue on Sep 20, 2023
  4. tucked commented on Sep 20, 2023

    @tucked

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

  5. p1c2u commented on Sep 20, 2023

    @p1c2u
    Collaborator

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

  6. Julian commented on Jan 4, 2024

    @Julian

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions