Opened 12 years ago

Closed 11 years ago

#18356 closed Bug (fixed)

Test Client response does not contain Context with nested requests

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

Description

get() and post() methods returns Response object, including context variable that was used to render the template that produced the response content.

However, if view calls another view before returning response, processing nested view will disconnect template_rendered signal returning no Context object.

I am attaching failing test case.

Attachments (1)

18356-test-client-context-lost-for-nested-views.diff (3.4 KB ) - added by bmihelac 12 years ago.

Download all attachments as: .zip

Change History (8)

comment:2 by bmihelac, 12 years ago

Fix for this can be in giving dispatch_uid unique value for each request. This is added to branch and pull request if there are no objections.

comment:3 by Aymeric Augustin, 12 years ago

Triage Stage: UnreviewedDesign decision needed
Type: UncategorizedBug

Well, the test client wasn't designed to be used from within a view.

Could you show us the patch that would fix this problem?

comment:4 by anonymous, 12 years ago

Changeset that fixes this issue is:

https://github.com/bmihelac/django-1/commit/86a374e4d149b9a11aedc69753ce91b46669d16e

(branch has test case and fix)

BTW, i found this issue while trying to fix django-test-utils, which has middleware that records context for every request made. Testing that necessarily leads to nesting requests in a test case.

in reply to:  4 comment:5 by bmihelac, 12 years ago

Accidentally posted this as anonymous.

comment:6 by Aymeric Augustin, 12 years ago

Triage Stage: Design decision neededAccepted

This is quite an edge case, but I can't see any downside to the fix.

comment:7 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 0cac4fbf699bb6a3de5f4a48c6e047a4dc6c2df7:

Fixed #18356 -- Gave the test client signals.template_rendered call a unique dispatch_uid

This prevents the test client context from being lost when the client
is used in a nested fashion.

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