From e89b2a03a769e6b59379a5b3312d39a082653a03 Mon Sep 17 00:00:00 2001 From: Quy Vu <40758906+xquyvu@users.noreply.github.com> Date: Mon, 30 Oct 2023 16:30:38 +0000 Subject: [PATCH] Fix several jsonschema DeprecationWarning (#1128) * address DeprecationWarnings from jsonschema * use `referencing` for Python >= 3.8 * undo unrelated change by auto linter --- clearml/backend_api/session/request.py | 15 ++++++++++----- requirements.txt | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/clearml/backend_api/session/request.py b/clearml/backend_api/session/request.py index 2a85cb0c..9004127a 100644 --- a/clearml/backend_api/session/request.py +++ b/clearml/backend_api/session/request.py @@ -1,7 +1,14 @@ import abc -import jsonschema import six +from jsonschema.exceptions import FormatError, SchemaError, ValidationError + +try: + # Since `referencing`` only supports Python >= 3.8, this try-except blocks maintain support + # for earlier python versions. + from referencing.exceptions import Unresolvable +except ImportError: + from jsonschema.exceptions import RefResolutionError as Unresolvable from .apimodel import ApiModel from .datamodel import DataModel @@ -39,8 +46,7 @@ class BatchRequest(Request): _batched_request_cls = abc.abstractproperty() - _schema_errors = (jsonschema.SchemaError, jsonschema.ValidationError, jsonschema.FormatError, - jsonschema.RefResolutionError) + _schema_errors = (SchemaError, ValidationError, FormatError, Unresolvable) def __init__(self, requests, validate_requests=False, allow_raw_requests=True, **kwargs): super(BatchRequest, self).__init__(**kwargs) @@ -70,8 +76,7 @@ class BatchRequest(Request): for i, req in enumerate(self.requests): try: req.validate() - except (jsonschema.SchemaError, jsonschema.ValidationError, - jsonschema.FormatError, jsonschema.RefResolutionError) as e: + except (SchemaError, ValidationError, FormatError, Unresolvable) as e: raise Exception('Validation error in batch item #%d: %s' % (i, str(e))) def get_json(self): diff --git a/requirements.txt b/requirements.txt index 82654c24..f4862419 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ python-dateutil>=2.6.1 pyjwt>=2.4.0,<2.9.0 ; python_version > '3.5' pyjwt>=1.6.4,<2.0.0 ; python_version <= '3.5' PyYAML>=3.12 +referencing<0.40 ; python_version >= '3.8' requests>=2.20.0 six>=1.13.0 typing>=3.6.4 ; python_version < '3.5'