Skip to content

Commit

Permalink
chore(jsonschema): migrate from deprecated Validator.iter_errors (#5856)
Browse files Browse the repository at this point in the history
Deprecated message:
DeprecationWarning: Passing a schema to Validator.iter_errors is deprecated
and will be removed in a future release.
Call validator.evolve(schema=new_schema).iter_errors(...) instead.

Refs:
https://github.com/python-jsonschema/jsonschema/releases/tag/v4.0.0

GH-5175
  • Loading branch information
aciba90 committed Nov 13, 2024
1 parent 7f9a34f commit 3682325
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cloudinit/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ def get_jsonschema_validator():
**validator_kwargs,
)

# Add deprecation handling
def is_valid(self, instance, _schema=None, **__):
def is_valid_pre_4_0_0(self, instance, _schema=None, **__):
"""Override version of `is_valid`.
It does ignore instances of `SchemaDeprecationError`.
Expand All @@ -547,9 +546,27 @@ def is_valid(self, instance, _schema=None, **__):
)
return next(errors, None) is None

def is_valid(self, instance, _schema=None, **__):
"""Override version of `is_valid`.
It does ignore instances of `SchemaDeprecationError`.
"""
errors = filter(
lambda e: not isinstance( # pylint: disable=W1116
e, SchemaDeprecationError
),
self.evolve(schema=_schema).iter_errors(instance),
)
return next(errors, None) is None

# Add deprecation handling
is_valid_fn = is_valid_pre_4_0_0
if hasattr(cloudinitValidator, "evolve"):
is_valid_fn = is_valid

# this _could_ be an error, but it's not in this case
# https://github.com/python/mypy/issues/2427#issuecomment-1419206807
cloudinitValidator.is_valid = is_valid # type: ignore [method-assign]
cloudinitValidator.is_valid = is_valid_fn # type: ignore [method-assign]

return (cloudinitValidator, FormatChecker)

Expand Down

0 comments on commit 3682325

Please sign in to comment.