Fix DeprecationWarning of jsonschema

`jsonschema.draft4_format_checker` and also `jsonschema.FormatChecker.cls_checks`
are deprecated and DeprecationWarning appears every time so these make
logs a little dirty and also these attribute/classmethod will be removed
in the future.

Therefore `jsonschema.draft4_format_checker` should be replaced with
`jsonschema.Draft4Validator.FORMAT_CHECKER` and
`jsonschema.FormatChecker.cls_checks` should be replaced with
`jsonschema.Draft4Validator.FORMAT_CHECKER.checks`.

Eventually, DeprecationWarning for jsonschema will disappear with this
proposed fix.

Closes-Bug: #2008490
Change-Id: I1ef326b8ac17f4bbcbc718d13223da156b0e5ec3
This commit is contained in:
Nozomi Kawamoto 2023-02-25 00:33:46 +09:00
parent 07d83abc6b
commit d52fb8cb6d
1 changed files with 2 additions and 2 deletions

View File

@ -18,7 +18,7 @@ from oslo_utils import timeutils
# JSON Schema validator and format checker used for JSON Schema validation
JSONSCHEMA_VALIDATOR = jsonschema.Draft4Validator
FORMAT_CHECKER = jsonschema.draft4_format_checker
FORMAT_CHECKER = jsonschema.Draft4Validator.FORMAT_CHECKER
# NOTE(gmann): Add customized format checker for 'date-time' format because:
@ -39,7 +39,7 @@ def _validate_datetime_format(instance):
return True
@jsonschema.FormatChecker.cls_checks('base64')
@FORMAT_CHECKER.checks('base64')
def _validate_base64_format(instance):
try:
if isinstance(instance, str):