From 4bd0ab33272064cc4e44fe2d652ecf7a11b07274 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 2 Aug 2022 16:07:04 -0400 Subject: Adapt to new jsonschema versions This change provides fixes that were dectected by unit test failures with new jsonschema (and py310). The types argument has been removed in favor of providing a type_checker to jsonschema.validators.extend: https://github.com/python-jsonschema/jsonschema/issues/577 Closes-Bug: #1983412 Change-Id: I86f12b3d264320308e7f4841910fc21a6e8b3fa9 --- taskflow/utils/schema_utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/taskflow/utils/schema_utils.py b/taskflow/utils/schema_utils.py index 8d7c216..7f6b52d 100644 --- a/taskflow/utils/schema_utils.py +++ b/taskflow/utils/schema_utils.py @@ -17,12 +17,6 @@ import jsonschema from jsonschema import exceptions as schema_exc -# Special jsonschema validation types/adjustments. -_SCHEMA_TYPES = { - # See: https://github.com/Julian/jsonschema/issues/148 - 'array': (list, tuple), -} - # Expose these types so that people don't have to import the same exceptions. ValidationError = schema_exc.ValidationError @@ -31,4 +25,11 @@ SchemaError = schema_exc.SchemaError def schema_validate(data, schema): """Validates given data using provided json schema.""" - jsonschema.validate(data, schema, types=_SCHEMA_TYPES) + Validator = jsonschema.validators.validator_for(schema) + # Special jsonschema validation types/adjustments. + # See: https://github.com/Julian/jsonschema/issues/148 + type_checker = Validator.TYPE_CHECKER.redefine( + "array", lambda checker, data: isinstance(data, (list, tuple))) + TupleAllowingValidator = jsonschema.validators.extend( + Validator, type_checker=type_checker) + TupleAllowingValidator(schema).validate(data) -- cgit v1.2.1