Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated jsonschema.RefResolver with referencing.Registry #2023

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radoering
Copy link

Fixes #1786 (which was closed prematurely as pointed out in #1786 (comment))

Fixes the following deprecation warnings:

connexion/json_schema.py:18
  /home/randy/connexion/connexion/json_schema.py:18: DeprecationWarning: jsonschema.RefResolver is deprecated as of v4.18.0, in favor of the https://github.com/python-jsonschema/referencing library, which provides more compliant referencing behavior as well as more flexible APIs for customization. A future release will remove RefResolver. Please file a feature request (on referencing) if you are missing an API for the kind of customization you need.
    from jsonschema import Draft4Validator, RefResolver

connexion/json_schema.py:19
  /home/randy/connexion/connexion/json_schema.py:19: DeprecationWarning: jsonschema.exceptions.RefResolutionError is deprecated as of version 4.18.0. If you wish to catch potential reference resolution errors, directly catch referencing.exceptions.Unresolvable.
    from jsonschema.exceptions import RefResolutionError, ValidationError  # noqa

See also https://python-jsonschema.readthedocs.io/en/latest/referencing/#migrating-from-refresolver

@chrisinmtown
Copy link
Contributor

chrisinmtown commented Dec 31, 2024

Thanks for this, I'm a little tired of seeing those warnings every time I run tox. I hope someone can explain why the code test pipeline/workflow didn't run automatically on this PR, only the read-the-docs check?

@@ -13,9 +14,11 @@

import requests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the imports are grouped (1) python standard, (2) third party and (3) connexion. FWIW maybe it's worth sorting within categories (1) and (2) here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a sorting within categories: At first normal imports sorted alphabetically, then from imports sorted alphabetically.

If I change the order isort will complain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, I didn't spot that pattern, never mind!



def retrieve(uri: str) -> Resource:
parsed = urllib.parse.urlsplit(uri)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please consider adding pydoc for this new function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chrisinmtown
Copy link
Contributor

chrisinmtown commented Dec 31, 2024

The referencing library is in status Alpha and their issues board includes a ticket about very slow performance:

python-jsonschema/referencing#178

Did you notice any slowdown here?

@radoering radoering force-pushed the fix-jsonschema-refresolver-deprecation branch from ee04d60 to 5ba75c9 Compare December 31, 2024 15:55
@radoering
Copy link
Author

Did you notice any slowdown here?

I did not notice any slowdown in the tests. I did not try with larger schemas.

@radoering
Copy link
Author

I hope someone can explain why the code test pipeline/workflow didn't run automatically on this PR, only the read-the-docs check?

The workflow requires approval from a maintainer according to https://github.com/spec-first/connexion/actions

@radoering radoering force-pushed the fix-jsonschema-refresolver-deprecation branch from 5ba75c9 to 2d70dde Compare January 12, 2025 06:17
@FelixSchwarz
Copy link
Contributor

Thanks for this, I'm a little tired of seeing those warnings every time I run tox.

You can suppress warnings via pytest.ini:

[pytest]
...
filterwarnings =
    error
    # Connexion 3.1 -> jsonschema
    ignore:Accessing jsonschema.draft4_format_checker is deprecated and will be removed in a future release.:DeprecationWarning
    ignore:jsonschema.RefResolver is deprecated as of v4.18.0, in favor of:DeprecationWarning
    ignore:jsonschema.exceptions.RefResolutionError is deprecated as of version 4.18.0.:DeprecationWarning

I hope someone can explain why the code test pipeline/workflow didn't run automatically on this PR, only the read-the-docs check?

GitHub offers maintainers options to not run workflows for non-members or first-time contributors. I believe this was added because of security concerns (workflows might have access to secrets which the PR could exfiltrate) and abuse (e.g. using the workflow for crypto mining).

@chrisinmtown
Copy link
Contributor

Just my $0.02, FWIW I think the JSON schema people might have acted hastily in adding those deprecations. I am not sure my first impression is correct, but the recommended replacement (another github project) looks new, not quite ready, very Alpha status. Given other instabilities that seem to plague Connexion 3, taking on the risk of making this switch doesn't seem like something to rush into.

@radoering
Copy link
Author

The recommended replacement (referencing) is from the JSON schema people:

The first release was over two years ago.

And considering the "Alpha" status: I would not put too much into it. For example, black was beta until 2021 and much more stable than many other "stable" packages.

To be clear: I do not know how stable referencing is, but I think the arguments considering it unstable are not that strong.

@Stranger6667
Copy link

FWIW, referencing passes most of the official referencing test suite (except URI normalization) + jsonschema which uses referencing passes the official JSON Schema Test Suite except for 1 test case (quite a rare one I must say).

Additionally, I've successfully borrowed the referencing design in my jsonschema implementation (it is closer to 100% spec compliance than jsonschema and often >300x faster).

I.e. as one of the jsonschema implementers & users of referencing I want to say that referencing is a great piece of software I've been relying on for many years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Various jsonschema DeprecationWarnings
4 participants