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

Original request object is overwritten when using APIRequestFactory #3759

Closed
TheProdigyFilippo opened this issue Dec 19, 2015 · 4 comments
Closed

Comments

@TheProdigyFilippo
Copy link

Hi, I've found annoying bug when updated from DRF 3.1.3 to the newest 3.3.2. The bug makes many tests results misleading and useless. Sample of code for a quick view what's going on:

request = self.factory.post('/signup/application/', params)
view = views.UserSignUpView.as_view()
response = view(request)
... #  <= some validation using asserts. OK
print request.__dict__ # <= QueryDict in POST is empty. NOT OK!
# running view again with the same request
response = view(request)  # <= generates exception, because my serializer tries to use data from an empty QueryDict

Tested on 3.1.3 (OK), 3.2.5 (OK) and 3.3.2 (FAIL)

Couldn't debug enough, but in rest_framework/views.py file method APIView.dispatch returns invalid request in request = self.initialize_request(request, *args, **kwargs) (line 442).

File rest_framework/views.py didn't change from 3.2.5 to 3.3.2, but rest_framework/request.py file changed and I suppose the problem is somewhere here.

Best regards!

@xordoquy
Copy link
Collaborator

This looks a lot like #3592

@tomchristie
Copy link
Member

Passing a request to a view twice shouldn't necessarily be okay. Eg the stream may have already been consumed after the view is called the first time.

@TheProdigyFilippo
Copy link
Author

I agree with you that it shouldn't necessarily be ok (in example with stream which you presented), but this code worked normally with two previous version lines of DRF (3.1.3 and 3.2.5), so it's quite strange.

@tomchristie
Copy link
Member

Might be able to consider cleanup, tho as it stands the issue isn't clear to me. If you can break this down to specifically what action cannot be taken twice on the request (rather than presenting this as 'view cannot be called twice') then we could reconsider.

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

No branches or pull requests

3 participants