Opened 9 years ago

Closed 8 years ago

Last modified 5 years ago

#7416 closed (fixed)

Test Client Loses session when login is called

Reported by: lakin.wecker@… Owned by: Eric Holscher
Component: Testing framework Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

If data is put into the session by a view during a test, and then subsequently in the same test the client.login method is used on the test client, the client loses all session data previously in it.

It appears to be due to this line:
http://code.djangoproject.com/browser/django/trunk/django/test/client.py?rev=7583#L258

I quickly changed that line to:

request.session = self.session# engine.SessionStore()

Which seems more correct, but I haven't run the tests to see if it's right or not.

Attachments (2)

testclient-session.diff (589 bytes) - added by Eric Holscher 8 years ago.
Simple patch implementing this.
testbed.tar.bz2 (9.8 KB) - added by Eric Holscher 8 years ago.
A project that shows the bug.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by Eric Holscher

Attachment: testclient-session.diff added

Simple patch implementing this.

comment:1 Changed 8 years ago by Eric Holscher

Has patch: set
milestone: 1.0
Needs tests: set
Owner: changed from nobody to Eric Holscher
Status: newassigned

Added a simple patch. Probably needs to be better, but this is a bug, line 56-57 in init of contrib/auth:

request.session[SESSION_KEY] = user.id
request.session[BACKEND_SESSION_KEY] = user.backend

Sets the existing session with the user Id.

comment:2 Changed 8 years ago by Eric Holscher

Triage Stage: UnreviewedAccepted

Changed 8 years ago by Eric Holscher

Attachment: testbed.tar.bz2 added

A project that shows the bug.

comment:3 Changed 8 years ago by Eric Holscher

Attached is a project and app that show the bug in the trunk version. The patch above fixes it. I didn't test too much more, but it appears to be working. I don't know if request.session is ever None (if it is, will that raise an error?)

comment:4 Changed 8 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [8372]) Fixed #7416: Modified test client to preserve session when a user logs in. Thanks to lakin.wecker@… for the report and Eric Holscher for the patch and test case.

comment:5 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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