Opened 7 years ago

Closed 6 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


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 7 years ago.

Download all attachments as: .zip

Change History (8)

comment:2 Changed 7 years ago by bmihelac

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 Changed 7 years ago by Aymeric Augustin

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 Changed 7 years ago by anonymous

Changeset that fixes this issue is:

(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.

comment:5 in reply to:  4 Changed 7 years ago by bmihelac

Accidentally posted this as anonymous.

comment:6 Changed 6 years ago by Aymeric Augustin

Triage Stage: Design decision neededAccepted

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

comment:7 Changed 6 years ago by Tim Graham <timograham@…>

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