Drf-yasg: Second request to docs fails with AttributeError

Created on 15 Dec 2017  路  4Comments  路  Source: axnsan12/drf-yasg

Steps to reproduce:

  1. Create django project with manage.py startproject, add "drf_yasg" to INSTALLED_APPS.
  2. urls.py:
from django.conf.urls import url
from django.contrib import admin
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

schema_view = get_schema_view(
    openapi.Info(
        title="Snippets API",
        default_version='v1'
    ),
    public=True,
    permission_classes=(permissions.AllowAny,)
)

urlpatterns += [
    url(r'swagger/$', schema_view.with_ui('swagger', cache_timeout=None), name='schema-swagger-ui'),
    url(r'redoc/$', schema_view.with_ui('redoc', cache_timeout=None), name='schema-redoc'),
]
  1. Start a server with manage.py runserver, first page request correctly shows docs UI, second one fails with AttributeError (trace below)
[15/Dec/2017 11:26:52] "GET /redoc/?format=openapi HTTP/1.1" 200 219
Internal Server Error: /redoc/
Traceback (most recent call last):
  File "/code/mkurnikov/.virtualenvs/project_name/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/code/mkurnikov/.virtualenvs/project_name/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/code/mkurnikov/.virtualenvs/project_name/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/code/mkurnikov/.virtualenvs/project_name/lib/python3.6/site-packages/drf_yasg/views.py", line 33, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/code/mkurnikov/.virtualenvs/project_name/lib/python3.6/site-packages/django/utils/decorators.py", line 141, in _wrapped_view
    result = middleware.process_request(request)
  File "/code/mkurnikov/.virtualenvs/project_name/lib/python3.6/site-packages/django/middleware/cache.py", line 137, in process_request
    response = self.cache.get(cache_key)
  File "/code/mkurnikov/.virtualenv/sproject_name/lib/python3.6/site-packages/django/core/cache/backends/locmem.py", line 54, in get
    return pickle.loads(pickled)
  File "/code/mkurnikov/.virtualenvs/project_name/lib/python3.6/site-packages/drf_yasg/openapi.py", line 190, in __init__
    self.info.version = _version or info._default_version
AttributeError: 'NoneType' object has no attribute '_default_version'

Django 1.11.7, Python 3.6.3, DRF 3.7.3

bug

Most helpful comment

Huh, this seems to be related to caching. I think I know how I managed to break it, will try to push a fix today.

Workaround for now is to set cache_timeout to 0, I guess...

All 4 comments

Huh, this seems to be related to caching. I think I know how I managed to break it, will try to push a fix today.

Workaround for now is to set cache_timeout to 0, I guess...

Ok, thanks a lot.

Project is great by the way, thank you for it.

Fixed and pushed to pypi. Can you confirm that it works for you?

Yes, works for me. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agethecoolguy picture agethecoolguy  路  4Comments

therefromhere picture therefromhere  路  3Comments

littlehome-eugene picture littlehome-eugene  路  4Comments

tiltec picture tiltec  路  4Comments

beaugunderson picture beaugunderson  路  5Comments