Opened 11 years ago
Closed 11 years ago
#22582 closed Bug (worksforme)
Document the use of mutable objects in request.session
Reported by: | PKL | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Ive seen several colleagues being bitten when trying to add values to lists/dicts that they stored in sessions.
It should be very explicit, yelled, in the session docs, that mutable values must be handled with care, and that only top-level assignements are detected by the session (and thus pushed to the session stored on save). All other modifications have good chances to be lost after the request is over.
That behaviour of the django session is very similar to all object stores (ZODB, shove, bdb...), but people are rarely aware of that "mutation detection" issue, so this trap had better be displayed everywhere. B-)
There is a section that discusses this: https://docs.djangoproject.com/en/dev/topics/http/sessions/#when-sessions-are-saved