Django

Code

Ticket #7416 (closed: fixed)

Opened 6 months ago

Last modified 4 months ago

Test Client Loses session when login is called

Reported by: lakin.wecker@gmail.com Assigned to: ericholscher
Milestone: 1.0 Component: Testing framework
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

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

testclient-session.diff (0.6 kB) - added by ericholscher on 08/08/08 10:03:30.
Simple patch implementing this.
testbed.tar.bz2 (9.8 kB) - added by ericholscher on 08/11/08 23:02:36.
A project that shows the bug.

Change History

08/08/08 10:03:30 changed by ericholscher

  • attachment testclient-session.diff added.

Simple patch implementing this.

08/08/08 10:05:54 changed by ericholscher

  • status changed from new to assigned.
  • needs_better_patch changed.
  • needs_tests set to 1.
  • milestone set to 1.0.
  • owner changed from nobody to ericholscher.
  • needs_docs changed.
  • has_patch set to 1.

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.

08/08/08 11:45:37 changed by ericholscher

  • stage changed from Unreviewed to Accepted.

08/11/08 23:02:36 changed by ericholscher

  • attachment testbed.tar.bz2 added.

A project that shows the bug.

08/11/08 23:03:33 changed by ericholscher

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?)

08/15/08 07:08:31 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

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


Add/Change #7416 (Test Client Loses session when login is called)




Change Properties
Action