Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 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: UI/UX:

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 4 years ago.
sessions.2.diff (1.3 KB) - added by elbarto 4 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 4 years ago by donspaulding

  • Component changed from Uncategorized to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

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 Changed 4 years ago by elbarto

  • Owner changed from nobody to elbarto

Changed 4 years ago by elbarto

comment:4 Changed 4 years ago by elbarto

  • Has patch set

comment:5 Changed 4 years ago by elbarto

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.

Changed 4 years ago by elbarto

comment:6 Changed 4 years ago by timo

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

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

comment:7 Changed 4 years ago by timo

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

Backport of r15053 from trunk.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.