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

Migrate away from abandoned coreapi/coreschema dependency #389

Open
ghost opened this issue Jun 20, 2019 · 15 comments
Open

Migrate away from abandoned coreapi/coreschema dependency #389

ghost opened this issue Jun 20, 2019 · 15 comments
Labels
dependencies Dependencies

Comments

@ghost
Copy link

ghost commented Jun 20, 2019

Hi there,

I've just noticed that this library depends on the coreapi which has been deprecated. What is the strategy going forward to work around this?

As per the coreapi github page:

DEPRECATION NOTICE: As of djangorestframework 3.9, the plan is to phase out CoreAPI in favor of OpenAPI as the default schema representation. New projects should consider using OpenAPI rather than CoreAPI. See the DRF 3.9 release announcment for more details.
@axnsan12
Copy link
Owner

Well, to be honest, if the OpenAPI implementation in DRF is up to snuff, the plan would be to deprecate this library altogether 🙂 Time will tell.

Otherwise, we'll have to review which parts of coreapi are used here and how we can replace them.

@onegreyonewhite
Copy link
Contributor

@axnsan12 You cant drop coreapi until in rest_framework.schemas.corepai.SchemaGenerator is used and DRF<3.11. But you can stop using coreapi imports. Check #588 for it.

@johnthagen
Copy link
Collaborator

johnthagen commented Jun 22, 2020

Another benefit of removing the dependency on coreapi is that coreapi depends on requests, which depends on chardet. chardet is LGPL licensed which presents problems for developers wanting to package their application as a binary using PyInstaller or PyOxidizer (psf/requests#4417).

@johnthagen
Copy link
Collaborator

Migrating issue details from JoelLefkowitz#60. Given that this is a long-term maintenance risk for the project, I am going to pin this issue for more visibility.

From the core-api repo:

DEPRECATION NOTICE: As of djangorestframework 3.9, the plan is to phase out CoreAPI in favor of OpenAPI as the default schema representation. New projects should consider using OpenAPI rather than CoreAPI. See the DRF 3.9 release announcment for more details.

DRF will soon be raising deprecation warnings for CoreAPI schemas and they will be removed in DRF 3.14. I haven't looked closely enough at drf-yasg2 to know if this will affect this package, or if we only rely on coreapi directly rather than through DRF itself.

The coreapi Python package is frozen and has not seen a release in 3 years. It was last tested on Python 3.6. This is a liability for the long term health of this project. This upstream issue would have broken drf-yasg[2] on Python 3.10, but a maintainer took over one of coreapi's frozen dependencies, itypes and fixed the issue.

Another benefit of removing the dependency on coreapi is that coreapi depends on requests, which depends on chardet. chardet is LGPL licensed which presents problems for developers wanting to package their application as a binary using PyInstaller or PyOxidizer (psf/requests#4417).

Seems like we should try to identify and migrate over the parts of coreapi that are needed for drf-yasg2.

coreapi also brings in coreschema which is used by drf-yasg2. coreschema has also not been maintained for 3 years.

@johnthagen johnthagen pinned this issue Oct 26, 2020
@johnthagen johnthagen changed the title coreapi is deprecated Migrate away from abandoned coreapi/coreschema dependency Oct 26, 2020
@axnsan12
Copy link
Owner

We depend on the coreapi for filters (in particular: django-filter) and paginators compat https://github.com/axnsan12/drf-yasg/blob/master/src/drf_yasg/inspectors/query.py

I imagine this could be replaced to use some new interface which is now used by DRF for its openapi schema

@johnthagen
Copy link
Collaborator

In case it helps, I also made a listing of everywhere coreapi and coreschema are used in the drf-yasg2 fork for reference.

Here is the comment: JoelLefkowitz#60 (comment)

It seems that potentially they could be tackled independently?

@axnsan12
Copy link
Owner

axnsan12 commented Oct 26, 2020

The coreapi.compat ones should be easy since it was just used as a lazy python 2 compatibility shim.

urlparse -> from urllib.parse
force_bytes -> from django.utils

@axnsan12
Copy link
Owner

@axnsan12
Copy link
Owner

axnsan12 commented Oct 26, 2020

Those APIs were added in DRF 3.10 so we are already clear from a compatibility pov to use them unconditionally (and drop coreapi/coreschema completely):

encode/django-rest-framework@37f210a

@johnthagen
Copy link
Collaborator

When starting some work on this in #664, I discovered there is another hidden dependency on coreapi here:

self._gen = SchemaGenerator(info.title, url, info.get('description', ''), patterns, urlconf)

DRF will throw an exception from rest_framework.schemas.coreapi.SchemaGenerator if coreapi is not installed:

https://github.com/encode/django-rest-framework/blob/04e0c2b9ab6616a28148ce32e2d19858ccfe6c69/rest_framework/schemas/coreapi.py#L120

@johnthagen
Copy link
Collaborator

johnthagen commented Oct 27, 2020

Okay, I've confirmed that the remaining coreapi usage will start throwing RemovedInDRF315Warnings starting in DRF 3.13 and will be removed in DRF 3.15: encode/django-rest-framework#7519

So we have a relatively short timeline to avoid warnings being generated in drf-yasg projects and then later actual breakages.

@johnthagen
Copy link
Collaborator

For anyone still tracking this (I've personally ported to drf-spectacular DRF just merged in the DeprecationWarnings to remove coreapi support that drf-yasg relies on

@sevdog
Copy link

sevdog commented Jun 20, 2023

There are a couple of configs which conflicts with #854

'DEFAULT_FILTER_INSPECTORS': [
'drf_yasg.inspectors.CoreAPICompatInspector',
],
'DEFAULT_PAGINATOR_INSPECTORS': [
'drf_yasg.inspectors.DjangoRestResponsePagination',
'drf_yasg.inspectors.CoreAPICompatInspector',
],

As of now these are still pinned to the old coreapi ones, this causes swagger generation to crash due to the fact that by default it tries to invoke some DRF methods which requires coreapi.

@onegreyonewhite
Copy link
Contributor

There are a couple of configs which conflicts with #854

'DEFAULT_FILTER_INSPECTORS': [
'drf_yasg.inspectors.CoreAPICompatInspector',
],
'DEFAULT_PAGINATOR_INSPECTORS': [
'drf_yasg.inspectors.DjangoRestResponsePagination',
'drf_yasg.inspectors.CoreAPICompatInspector',
],

As of now these are still pinned to the old coreapi ones, this causes swagger generation to crash due to the fact that by default it tries to invoke some DRF methods which requires coreapi.

@sevdog Good point. It is high time to switch to receiving parameters not from coreapi. But this is a minor/major change. I can create a class that will take other methods from the paginator and filters, but making it default is better for the maintainer (@JoelLefkowitz )

@darrinmn9
Copy link

darrinmn9 commented Jul 19, 2023

just an fyi, there is now another deprecation warning related to the coreapi package, that will be removed in 3.13

/python3.11/site-packages/coreapi/codecs/download.py:5:
DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13

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

No branches or pull requests

5 participants