DeprecationWarning with jsonschema 4.0.0 (validator.py:315)
slayoo opened this issue · comments
Since 4.0.0 release of jsonschema (https://github.com/Julian/jsonschema/releases/tag/v4.0.0), the following error started popping out in our CI logs:
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/nbformat/v4/nbbase.py:100: in output_from_msg
return new_output(output_type=msg_type,
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/nbformat/v4/nbbase.py:67: in new_output
validate(output, output_type)
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/nbformat/v4/nbbase.py:39: in validate
return validate(node, ref=ref, version=nbformat)
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/nbformat/validator.py:268: in validate
for error in iter_validate(nbdict, ref=ref, version=version,
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/nbformat/validator.py:315: in iter_validate
for error in errors:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = Draft4Validator(schema={'$schema': 'http://json-...ft-04/schema#', 'additionalProperties': False, 'definitions': {'cel...utput_type', 'data', 'metadata'], ...}, ...}, 'description': 'Jupyter Note... JSON schema.', ...}, format_checker=None)
instance = {'output_type': 'display_data', 'metadata': {'needs_background': 'light'}, 'data': {'text/plain': '<Figure size 432x28...5t9nMOz+3R8Gt9MVaN9e+2lkAQEWlyzVK6ERGRChToRUSanAK9iEiTU6AXEWlyCvQiIk1OgV5EpMkp0IuINLn/BGTFCzE4DS3BAAAAAElFTkSuQmCC\n'}}
_schema = {'$ref': '#/definitions/display_data'}
def iter_errors(self, instance, _schema=None):
if _schema is not None:
> warnings.warn(
(
"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."
),
DeprecationWarning,
)
E 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.
HTH,
Would be great release a fix,
Thanks,
Sylwester
Note that jsonschema 4.x was released yesterday, and has already had some bugfix releases.
In the near term, you could:
- pin to
<4
in your repo's CI - add this to your repo's filtered warnings... that breaking release won't be tomorrow
- submit a PR to this repo, if you know how to fix it ❤️
Would a PR that does this in a minor release of nbformat fix this DeprecationWarning?:
DeprecationWarning: Passing a schema to
Validator.iter_errors
is deprecated and will be removed in a future release. Callvalidator.evolve(schema=new_schema).iter_errors(...)
instead
Does the fix need to be backwards-compatible or can this one call be updated along with the version constraint?
Hi @westurner it could be backwards, by using a try/except if there is an attributerror (assuming the evolve call is not on older versions)
try:
iterator = validator.evolve(schema=new_schema).iter_errors(...)
except AttributeError:
iterator = Validator.iter_errors(...)
If there's no risk of memory leak from keeping the configured validator in scope, IMHO that sounds like a justified PERF optimization that justifies a couple more lines of changes.
FWIW if anyone else is seeing this as a warning in pytest (e.g. via testbook), adding this to pytest's config will ignore the warning:
[pytest]
filterwarnings =
ignore:Passing a schema to Validator\.iter_errors is deprecated and will be removed in a future release\.:DeprecationWarning:jsonschema\.validators