Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#13020 closed (fixed)

Django session documentation is wrong

Reported by: bryan Owned by: elbarto
Component: Documentation Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

http://docs.djangoproject.com/en/1.1/topics/http/sessions/#using-sessions-out-of-views

You shouldn't pass a session_key into SessionStore, that gets generated automatically when you save() it.

>>> from django.contrib.sessions.backends.db import SessionStore
>>> s = SessionStore()
>>> s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10)
>>> s['last_login']
datetime.datetime(2005, 8, 20, 13, 35, 0)
>>> s.save()
>>> s.session_key
'2b1189a188b44ad18c35e113ac6ceead
>>> from django.contrib.sessions.models import Session
>>> s = Session.objects.get(pk='2b1189a188b44ad18c35e113ac6ceead')
>>> s.expire_date
datetime.datetime(2005, 8, 20, 13, 35, 12)

Attachments (2)

sessions.diff (925 bytes ) - added by elbarto 14 years ago.
sessions.2.diff (1.3 KB ) - added by elbarto 14 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by donspaulding, 15 years ago

Component: UncategorizedDocumentation

comment:2 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

You *should* provide a key if you know which session you want to use. If provide a session key, Django will use that key specifically. If you omit the key, one will be generated. However, as far as I can tell, the fact that a session key will be generated if one isn't provided isn't a documented behaviour.

comment:3 by elbarto, 14 years ago

Owner: changed from nobody to elbarto

by elbarto, 14 years ago

Attachment: sessions.diff added

comment:4 by elbarto, 14 years ago

Has patch: set

comment:5 by elbarto, 14 years ago

I have notice that it still missing an import (datetime) in current source and also in my patch.

When:

slast_login = datetime.datetime(2005, 8, 20, 13, 35, 10)

It returns:

Traceback (most recent call last):

File "<console>", line 1, in <module>

NameError: name 'datetime' is not defined

I fixed it in new patch.

by elbarto, 14 years ago

Attachment: sessions.2.diff added

comment:6 by Tim Graham, 14 years ago

Resolution: fixed
Status: newclosed

(In [15053]) Fixed #13020 - add clarifying note to SessionStore. thanks elbarto for the patch.

comment:7 by Tim Graham, 14 years ago

(In [15054]) [1.2.X] Fixed #13020 - add clarifying note to SessionStore. thanks elbarto for the patch.

Backport of r15053 from trunk.

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