Opened 4 years ago

Closed 4 years ago

#16106 closed Bug (duplicate)

Test client session not set for unauthenticated requests

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


In it says that I can do something like this in my tests:

def test_something(self):
    session = self.client.session
    session['somekey'] = 'test'

However if the client is not logged-in, self.client.session returns a dict which will result in an AttributeError.

Change History (2)

comment:1 Changed 4 years ago by humanfromearth

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Test client session for unauthenticated users to Test client session not set for unauthenticated requests

I found a workaround for this bug. Just access a view that sets the session for you. For example:

session = self.client.session
session['some_var'] = 'value'

do stuff

comment:2 Changed 4 years ago by prestontimmons

  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the report. This issue is documented in #15740 and #10899, which has a patch to fix this. Closing this one as a duplicate.

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