diff options
author | Corey Bryant <corey.bryant@canonical.com> | 2022-08-02 16:07:04 -0400 |
---|---|---|
committer | Corey Bryant <corey.bryant@canonical.com> | 2022-08-03 15:16:02 -0400 |
commit | 4bd0ab33272064cc4e44fe2d652ecf7a11b07274 (patch) | |
tree | e2fbc1daa88473c4d48c2d6f4c209f94ed523c42 | |
parent | 185e6c4a39f622bc46ba4b2d972bd8c7ed975888 (diff) | |
download | taskflow-4bd0ab33272064cc4e44fe2d652ecf7a11b07274.tar.gz |
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
-rw-r--r-- | taskflow/utils/schema_utils.py | 15 |
1 files 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) |