django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

`coreapi` must be installed for schema support with Python 3.10

Open variable opened this issue 1 year ago • 1 comments

It appears coreapi is not python3.10 compat, one of my external lib that imports the SchemaGenerator from rest_framework.schemas will causes the error: coreapi must be installed for schema support with Python 3.10`

from rest_framework.schemas import (
    SchemaGenerator as BaseSchemaGenerator,
)

The underlining exception when importing coreapi was:

ImportError: cannot import name 'Mapping' from 'collections' (/opt/homebrew/Cellar/[email protected]/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

Is there a way to resolve this?

variable avatar May 30 '24 00:05 variable

  1. stop using it as it is deprecated in DRF so not suggested anymore.
  2. we can fix the compatibility issue in the mean time.

auvipy avatar Jun 03 '24 04:06 auvipy

@variable which version of coreapi are you using? DRF uses coreapi==2.3.1 to run its test suite and the problem doesn't happen in tests, despite a similar import being done in tests:

https://github.com/encode/django-rest-framework/blob/f113ab6b68e5ab8c395a93f168fe46c77c05b324/tests/schemas/test_coreapi.py#L24-L26

I tried to run the tests with Python 3.10 against the latest version of coreapi (2.3.3) and couldn't reproduce the problem either. Finally I searched Mapping in the codebase of coreapi and couldn't find any mention of it.

So regarding point 2 above, I don't think there is anything to do. This issue seem invalid to me and unless OP can provide more details, it can probably be closed.

browniebroke avatar Aug 20 '24 08:08 browniebroke

@browniebroke I am running coreapi==2.3.3

variable avatar Aug 20 '24 23:08 variable

Somehow this issue is still present for me, even after upgrading all the main packages. Probably dependencies resolving still..not the best in python.

It's not about coreapi itself, but markupsafe package somewhere under the hood. I checked my installed version, seems I have MarkupSafe==0.23 which is quite old. That's even after django/drf/coreapi upgrades.
Also I'd want to notice, than inside of isolated environment everything seems resolving right, so problem only appears on non-fresh environment.

I see that coreapi doesn't provide any specific version requirements, so when I'm upgrading main packages, it doesn't really bother with upgrading dependencies (understandable, because no version requirements provided).
See here: https://github.com/core-api/python-client/blob/d264fd277a878ea40f9f75755e461f8a9418671f/setup.py#L65

As a result of tries and mistakes, I figured out that you need at least:

jinja2==3.1.4
markupsafe==2.1.5

Please note, manually installing setuptools is also might be a requirement.

I'm mad that I need to figure out working versions by myself.

P.S. Still considering built-in rest_framework.documentation as a good documentation. Too bad it's not supported and never mentioned in the docs.

yznts avatar Sep 10 '24 11:09 yznts