Skip to content

Suspected django 2 incompatibility in DRF >= 3.7.4 request.py __init__ method's request object #5836

Closed
@eschercode

Description

@eschercode

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

DRF >= 3.7.4 and Django 2

Try a basic view similar to this.

class FooList(generics.ListAPIView):
    permission_classes = (permissions.isAuthenticated,)
    model = Foo
    serializer_class = FooSerializer
    pagination_class = None

    def get_queryset(self):
        return Foo.objects.filter(business_logic_here)

More discussion here: https://groups.google.com/d/msg/django-rest-framework/mxzgI0n_VZg/ra-M95fhCgAJ

Expected behavior

Valid Http response

Actual behavior

Works fine in 3.7.3, fails in >= 3.7.4. Traceback: (assuming our venv is in /srv)

File “/srv/lib/python3.6/site-packages/django/core/handlers/exception.py” in inner
35.             response = get_response(request)
File “/srv/lib/python3.6/site-packages/django/core/handlers/base.py” in _get_response
128.                 response = self.process_exception_by_middleware(e, request)
File “/srv/lib/python3.6/site-packages/django/core/handlers/base.py” in _get_response
126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/srv/lib/python3.6/site-packages/django/views/decorators/csrf.py” in wrapped_view
54.         return view_func(*args, **kwargs)
File “/srv/lib/python3.6/site-packages/django/views/generic/base.py” in view
69.             return self.dispatch(request, *args, **kwargs)
File “/srv/lib/python3.6/site-packages/django/utils/decorators.py” in _wrapper
62.             return bound_func(*args, **kwargs)
File “/srv/lib/python3.6/site-packages/django/views/decorators/csrf.py” in wrapped_view
54.         return view_func(*args, **kwargs)
File “/srv/lib/python3.6/site-packages/django/views/generic/base.py” in view
69.             return self.dispatch(request, *args, **kwargs)
File “/srv/lib/python3.6/site-packages/rest_framework/views.py” in dispatch
494.             response = self.handle_exception(exc)
File “/srv/lib/python3.6/site-packages/rest_framework/views.py” in handle_exception
454.             self.raise_uncaught_exception(exc)
File “/srv/lib/python3.6/site-packages/rest_framework/views.py” in dispatch
491.             response = handler(request, *args, **kwargs)
File “/srv/lib/python3.6/site-packages/rest_framework/decorators.py” in handler
53.             return func(*args, **kwargs)
File “/srv/lib/python3.6/site-packages/django/utils/decorators.py” in bound_func
58.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File “/srv/lib/python3.6/site-packages/rest_framework/views.py” in dispatch
477.         request = self.initialize_request(request, *args, **kwargs)
File “/srv/lib/python3.6/site-packages/rest_framework/views.py” in initialize_request
381.             parser_context=parser_context
File “/srv/lib/python3.6/site-packages/rest_framework/request.py” in _init_
159.             .format(request.__class__.__module__, request.__class__.__name__)

Exception Type: AssertionError at /API/foo/the_pk/ Exception Value: The `request` argument must be an instance of `django.http.HttpRequest`, not `rest_framework.request.Request`.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions