5

Just tried to rebuild a container with DRF and drf-yasg. The exact same commit was passing all tests fine but is now falling over with the following exception:

ImportError: Could not import 'rest_framework.schemas.coreapi.AutoSchema' for API setting 'DEFAULT_SCHEMA_CLASS'. ModuleNotFoundError: No module named 'rest_framework.schemas.coreapi'.

Nothing else has changed, but it seems a newer package may have been included that broke the Swagger generator.

Anyone else experience similar?

So it seems pip was pulling DRF V3.10, which has some switch from CoreAPI to OpenAPI: https://www.django-rest-framework.org/community/3.10-announcement/ . Adding the line from the release documentation:

REST_FRAMEWORK = {
  ...
  'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}

did not seem to make any difference.

Stuart Buckingham
  • 1,574
  • 16
  • 25
  • 1
    You don't need `'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'` for drf-yasg. Are you sure this is not defined unexpectedly anywhere else? – yofee Jul 15 '19 at 21:55
  • Please add the complete traceback, I experienced something similar. – yofee Jul 15 '19 at 23:42

3 Answers3

5

I would presume your dependencies in requirements.txt are not specific enough, and rebuilding the container has installed a later version of djangorestframework.

Check for a line in your pipfile like djangorestframework>=3.9, and this should be changed to either pin a specific version djangorestframework==3.9, or pin it to a specific minor release so you will still receive bug fixes and security updates djangorestframework>=3.9,<3.10.

These lines can also be used directly with pip, incase your container build uses pip directly, e.g. pip install "djangorestframework>=3.9,<3.10"

A. J. Parr
  • 7,731
  • 2
  • 31
  • 46
1

It seems that installing coreapi seperately may help: pip install coreapi

mcan
  • 1,914
  • 3
  • 32
  • 53
-1
 pip3 install packaging

solve it!

Hamed Rostami
  • 1,670
  • 14
  • 16