Opened 16 years ago

Closed 16 years ago

Last modified 12 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: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

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 16 years ago.
Simple patch implementing this.
testbed.tar.bz2 (9.8 KB ) - added by Eric Holscher 16 years ago.
A project that shows the bug.

Download all attachments as: .zip

Change History (7)

by Eric Holscher, 16 years ago

Attachment: testclient-session.diff added

Simple patch implementing this.

comment:1 by Eric Holscher, 16 years ago

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 by Eric Holscher, 16 years ago

Triage Stage: UnreviewedAccepted

by Eric Holscher, 16 years ago

Attachment: testbed.tar.bz2 added

A project that shows the bug.

comment:3 by Eric Holscher, 16 years ago

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 by Russell Keith-Magee, 16 years ago

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 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

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