From 4e18031dcd75766b7a5dcc83e3658bff5f3ad1c1 Mon Sep 17 00:00:00 2001 From: Stefan Binder Date: Fri, 27 Jan 2023 22:44:21 +0100 Subject: [PATCH] Fix incompatibility with jsonschema < 4.5 (#2860) * Fix incompatibility with jsonschema < 4.17 * Add changelog entry for 4.2.2 * Fix jsonschema version in changelog --- altair/utils/schemapi.py | 7 ++++--- doc/releases/changes.rst | 7 +++++++ tools/schemapi/schemapi.py | 7 ++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/altair/utils/schemapi.py b/altair/utils/schemapi.py index f170acd3f..d3e1aef82 100644 --- a/altair/utils/schemapi.py +++ b/altair/utils/schemapi.py @@ -50,9 +50,10 @@ def validate_jsonschema(spec, schema, resolver=None): # e.g. '#/definitions/ValueDefWithCondition' would be a valid $ref in a Vega-Lite schema but # it is not a valid URI reference due to the characters such as '<'. - validator = JSONSCHEMA_VALIDATOR( - schema, format_checker=JSONSCHEMA_VALIDATOR.FORMAT_CHECKER, resolver=resolver - ) + validator_kwargs = {"resolver": resolver} + if hasattr(JSONSCHEMA_VALIDATOR, "FORMAT_CHECKER"): + validator_kwargs["format_checker"] = JSONSCHEMA_VALIDATOR.FORMAT_CHECKER + validator = JSONSCHEMA_VALIDATOR(schema, **validator_kwargs) error = jsonschema.exceptions.best_match(validator.iter_errors(spec)) if error is not None: raise error diff --git a/doc/releases/changes.rst b/doc/releases/changes.rst index bdcf44b31..a2598b2b3 100644 --- a/doc/releases/changes.rst +++ b/doc/releases/changes.rst @@ -3,6 +3,13 @@ Altair Change Log ================= +Version 4.2.2 (released XXX YY, 2023) +------------------------------------- + +Bug Fixes +~~~~~~~~~ +- Fix incompatibility with jsonschema < 4.5 which got introduced in Altair 4.2.1 (#2860). + Version 4.2.1 (released Jan 26, 2023) ------------------------------------- diff --git a/tools/schemapi/schemapi.py b/tools/schemapi/schemapi.py index 3844483a7..4949ba7f8 100644 --- a/tools/schemapi/schemapi.py +++ b/tools/schemapi/schemapi.py @@ -48,9 +48,10 @@ def validate_jsonschema(spec, schema, resolver=None): # e.g. '#/definitions/ValueDefWithCondition' would be a valid $ref in a Vega-Lite schema but # it is not a valid URI reference due to the characters such as '<'. - validator = JSONSCHEMA_VALIDATOR( - schema, format_checker=JSONSCHEMA_VALIDATOR.FORMAT_CHECKER, resolver=resolver - ) + validator_kwargs = {"resolver": resolver} + if hasattr(JSONSCHEMA_VALIDATOR, "FORMAT_CHECKER"): + validator_kwargs["format_checker"] = JSONSCHEMA_VALIDATOR.FORMAT_CHECKER + validator = JSONSCHEMA_VALIDATOR(schema, **validator_kwargs) error = jsonschema.exceptions.best_match(validator.iter_errors(spec)) if error is not None: raise error