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

Schema can not created in v. 0.15.0 #358

Closed
AlexElizard opened this issue Apr 5, 2021 · 7 comments
Closed

Schema can not created in v. 0.15.0 #358

AlexElizard opened this issue Apr 5, 2021 · 7 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@AlexElizard
Copy link

Schema can not created in v. 0.15.0.
In version 0.14.0, the problem is missing

Traceback v0.15.0

Traceback (most recent call last):
  File "/lib/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "./lib/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "./lib/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "./lib/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "./lib/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "./lib/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "./lib/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "./lib/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "./lib/site-packages/drf_spectacular/views.py", line 67, in get
    return self._get_schema_response(request)
  File "./lib/site-packages/drf_spectacular/views.py", line 71, in _get_schema_response
    return Response(generator.get_schema(request=request, public=self.serve_public))
  File "./lib/site-packages/drf_spectacular/generators.py", line 242, in get_schema
    paths=self.parse(request, public),
  File "./lib/site-packages/drf_spectacular/generators.py", line 216, in parse
    operation = view.schema.get_operation(
  File "./lib/site-packages/drf_spectacular/openapi.py", line 57, in get_operation
    operation['operationId'] = self.get_operation_id()
  File "./lib/site-packages/drf_spectacular/openapi.py", line 281, in get_operation_id
    tokenized_path = self._tokenize_path()
  File "./lib/site-packages/drf_spectacular/openapi.py", line 304, in _tokenize_path
    path = re.sub(
  File "./python/python39/lib/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "./python/python39/lib/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "./python/python39/lib/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "./python/python39/lib/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "./python/python39/lib/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "./python/python39/lib/sre_parse.py", line 511, in _parse
    sourceget()
  File "./python/python39/lib/sre_parse.py", line 256, in get
    self.__next()
  File "./python/python39/lib/sre_parse.py", line 245, in __next
    raise error("bad escape (end of pattern)",
re.error: bad escape (end of pattern) at position 1
[05/Apr/2021 10:50:13] "GET /swagger/schema/ HTTP/1.1" 500 176816
@tfranzel
Copy link
Owner

tfranzel commented Apr 5, 2021

ahh i think i see the problem. we introduced automatic estimation of the path prefix and we missed accounting for variables.

in the meantime you can restore old behavior with setting 'SCHEMA_PATH_PREFIX': '' instead of the default None.

@tfranzel
Copy link
Owner

tfranzel commented Apr 5, 2021

but it would be most helpful if you share how you paths look like to make sure we also cover your case.

@tfranzel tfranzel added bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Apr 5, 2021
@AlexElizard
Copy link
Author

AlexElizard commented Apr 5, 2021

but it would be most helpful if you share how you paths look like to make sure we also cover your case.

Standard paths offered by django rest framework and django. For example

# ./news/urls.py
router = SimpleRouter()
router.register('', NewsViewSet)

urlpatterns = [
    path('categories/', CategoryListAPIView.as_view()),
    path('', include(router.urls)),
]


# project urls
urlpatterns = [
        path('news/', include('news.urls')),
    ])),
]


if 'ckeditor_uploader' in settings.INSTALLED_APPS:
    urlpatterns.append(path('api/ckeditor/', include('ckeditor_uploader.urls')))

if 'drf_spectacular' in settings.INSTALLED_APPS:
    from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView

    urlpatterns.append(
        path('swagger/', include([
            path('', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
            path('schema/', SpectacularAPIView.as_view(), name='schema')
        ]))
    )

if settings.DEBUG:
    urlpatterns = urlpatterns + static(
        settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

    if 'debug_toolbar' in settings.INSTALLED_APPS:
        import debug_toolbar
        urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))

@AlexElizard
Copy link
Author

ahh i think i see the problem. we introduced automatic estimation of the path prefix and we missed accounting for variables.

in the meantime you can restore old behavior with setting 'SCHEMA_PATH_PREFIX': '' instead of the default None.

It is not working. For now I will stay on version 0.14.0

SPECTACULAR_DEFAULTS = {
    'SCHEMA_PATH_PREFIX': '',
}

@tfranzel
Copy link
Owner

tfranzel commented Apr 6, 2021

this must work as is turns off the introduced feature. SPECTACULAR_DEFAULTS is wrong in settings. SPECTACULAR_SETTINGS is the correct dictionary name. looks like the settings are not found.

can you install the master and test the bugfix (without the setting)? pip install -e git+https://github.com/tfranzel/drf-spectacular

@AlexElizard
Copy link
Author

AlexElizard commented Apr 8, 2021

can you install the master and test the bugfix (without the setting)? pip install -e git+https://github.com/tfranzel/drf-spectacular

it is working

@tfranzel
Copy link
Owner

tfranzel commented Apr 8, 2021

released 0.15.1

@tfranzel tfranzel closed this as completed Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants