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

SWAGGER_SETTINGS['LOGIN_URL'] does not work with reverse_lazy #209

Closed
linevych opened this issue Sep 12, 2018 · 2 comments
Closed

SWAGGER_SETTINGS['LOGIN_URL'] does not work with reverse_lazy #209

linevych opened this issue Sep 12, 2018 · 2 comments
Assignees
Labels
bug Bug report/fix

Comments

@linevych
Copy link

Versions

  • drf-yasg==1.10.1
  • djangorestframework==3.8.2
  • Django==2.0.6
  • Python 3.6.5

Settings

SWAGGER_SETTINGS = {
    'DEFAULT_INFO': 'project_name.swagger_urls.api_info,
}

LOGIN_URL = reverse_lazy('custom_view_name')

Traceback

Traceback (most recent call last):
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/django/core/handlers/base.py", line 158, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/django/core/handlers/base.py", line 156, in _get_response
    response = response.render()
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/django/template/response.py", line 106, in render
    self.content = self.rendered_content
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/rest_framework/response.py", line 72, in rendered_content
    ret = renderer.render(self.data, accepted_media_type, context)
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/drf_yasg/renderers.py", line 71, in render
    self.set_context(renderer_context, swagger)
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/drf_yasg/renderers.py", line 121, in set_context
    super(SwaggerUIRenderer, self).set_context(renderer_context, swagger)
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/drf_yasg/renderers.py", line 83, in set_context
    renderer_context.update(self.get_auth_urls())
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/drf_yasg/renderers.py", line 103, in get_auth_urls
    'LOGIN_URL': self.resolve_url(swagger_settings.LOGIN_URL),
  File "/home/anton/.virtualenvs/slated/lib/python3.6/site-packages/drf_yasg/renderers.py", line 92, in resolve_url
    to, args, kwargs = to
ValueError: too many values to unpack (expected 3)

Debugging info

screenshot-2018-09-12 22_58_30

@axnsan12
Copy link
Owner

Whoops.

@axnsan12 axnsan12 self-assigned this Sep 12, 2018
@axnsan12 axnsan12 added the bug Bug report/fix label Sep 12, 2018
@linevych
Copy link
Author

linevych commented Sep 12, 2018

Possible fix:

    def resolve_url(self, to):
        if to is None:
            return None

        from django.utils.functional import Promise
        to = str(to) if isinstance(to, Promise) else to

        args, kwargs = None, None

        if not isinstance(to, six.string_types):
            if len(to) > 2:
                to, args, kwargs = to
            elif len(to) == 2:
                to, kwargs = to

        args = args or ()
        kwargs = kwargs or {}

        return resolve_url(to, *args, **kwargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report/fix
Projects
None yet
Development

No branches or pull requests

2 participants