Opened 9 years ago

Closed 9 years ago

#24722 closed Bug (invalid)

test client puts different results in response.context when nested view is redirected with process_request vs process_response middleware

Reported by: Jay Cox Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords: test client
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jay Cox)

When using the test client:

When a view calls another view and middleware causes the inner view to redirect - the contents of response.context will be different depending on if it was process_request, or process_response that initiated the redirect.

Test case for this error is in gitub:
https://github.com/electricjay/django/tree/test_client_nested_testcase

This problem was discovered when creating the pull request https://github.com/django/django/pull/4574 for ticket #24696

Change History (3)

comment:1 by Jay Cox, 9 years ago

Description: modified (diff)

comment:2 by Tim Graham, 9 years ago

Component: UncategorizedTesting framework
Triage Stage: UnreviewedAccepted

comment:3 by Jay Cox, 9 years ago

Resolution: invalid
Status: newclosed

I have tracked the cause down and I no longer think this is a bug with the test client.

When the redirect happens in process_response a 404 response is created using a template before process_response is run. Thus the test client is legitimately(?) adding the context from the 404 response to the context of the response that is ultimately returned.

I suggest only modifying the test test_client_regress.tests.ContextTests.test_nested_requests to not trigger the common middleware.

Note: See TracTickets for help on using tickets.
Back to Top