Skip to content

initialize_request in view.py converts the request in Request without checking the incoming request type #2771

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
a6kme opened this issue Mar 27, 2015 · 3 comments

Comments

@a6kme
Copy link

a6kme commented Mar 27, 2015

I am trying to call a class baed view from another class based view using This SO post. I called a class baed view by passing in the request like MyClassBasedView.as_view()(request). When I tried to access the HTTPRequest from request, I had to access it like request._request._request, instead of request._request. I checked the code in views.py and it is converting the incoming request to Request without checking the instance of request. I managed it by using MyClassBasedView.as_view()(request._request)
This is my first reporting of an issue. Please be gentle if I violated any guideline.

@tomchristie
Copy link
Member

Calling a view from another view isn't really supported behavior so odd things may happen, but we could modify the behavior you saw eg. by modifying https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/request.py#L138 slightly so that passing a Request to Request uses the only underlying HTTPRequest, rather then ending up with the convoluted ._request._request.

There might also be some cases where that'd be helpful if folks are manually constructing Request instances in test cases and passing them to the view.

I'm slightly unclear why you'd need to access the underlying HTTPRequest instance tho, as the proxying behavior we provide should generally ensure that it's not needed.

@olivergeorge
Copy link

I think this is related to a use case I'm trying to implement which is effectively batching up data from many views.

@tomchristie
Copy link
Member

If we do nothing else we should at least raise an error in this case.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants