Skip to content

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?

from collections.abc import Mapping
from copy import deepcopy

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.

@radoering radoering force-pushed the fix-jsonschema-refresolver-deprecation branch from 2d70dde to 8cbc067 Compare May 15, 2025 14:41
@briceburg
Copy link

briceburg commented Aug 2, 2025

Curios re: the progress on this? IMO pytest should simply work for our users without a deprecation warning. We can port everything that refResolver did to use referencing equivalents. It's as easy as providing a custom resolver to handle all the relative pathing / http lookups / &c.

it would be nice to use an @referencing.retrieval.to_cached_resource() annotation on the method... but it's going to be more complicated than that... ;) and can implement its own caching as necessary. https://referencing.readthedocs.io/en/stable/intro/

is there a review process or feedback/progress on any existing PRs? would this project accept another? I feel that getting referencing in place is going to be a stepping stone towards finally supporting the openapi 3.1 spec.... and in meantime we can limit resolver to using Draft7 schemas & validators.

@briceburg
Copy link

@RobbeSneyders was closed prematurely -- see #1786 (comment) ... curious what we can do to get a fix for this. anyone using connexion w/ pytest is seeing:

=========================== test session starts ===========================
platform linux -- Python 3.13.5, pytest-8.4.1, pluggy-1.6.0
rootdir: /foo
configfile: pyproject.toml
plugins: anyio-4.9.0
collected 6 items                                                         

tests/api/test_players.py .                                         [ 16%]
tests/api/test_station_presets.py .                                 [ 33%]
tests/test_schemas.py ....                                          [100%]

============================ warnings summary =============================
venv/lib/python3.13/site-packages/connexion/json_schema.py:16
venv/lib/python3.13/site-packages/connexion/json_schema.py:16
  /foo/venv/lib/python3.13/site-packages/connexion/json_schema.py:16: 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

... and this will not go away util we replace RefResolver with referencing per this PR, or another approach??

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

5 participants