Opened 15 months ago

Last modified 3 weeks ago

#22634 assigned Cleanup/optimization

Making Session model and SessionStore classes more easily extendable

Reported by: sergeykolosov Owned by: sergeykolosov
Component: contrib.sessions Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


While developing a feature the involves adding an extra database field to the Session model (thus creating a new session backend based on Django's one), I faced the need to copy almost everything from, backends/ and backends/

The reason why one have to do that, is the way that Session model is imported and used inside backends/ and backends/, and the way SessionStore class imported and used inside

Since the custom backend is a part of a shared package, which is intended to be used with multiple versions of Django, it's challenging to do that given the above.

I suggest the following changes:

  • extract an abstract base model from Session;
  • make Session class a property of SessionStore class, removing hardcoded usages;
  • make key_prefix a property of SessionStore, defaulting to KEY_PREFIX;
  • (anything else to make building a custom backend based on Django's one easier).

Change History (8)

comment:1 Changed 15 months ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Sounds good to me - the sessions framework is designed to be extensible through backends, so we should be doing whatever we can to maximise reuse.

comment:2 Changed 15 months ago by sergeykolosov

  • Owner changed from nobody to sergeykolosov
  • Status changed from new to assigned

comment:3 Changed 15 months ago by sergeykolosov

  • Has patch set

comment:4 Changed 15 months ago by sergeykolosov

PR updated (documentation and release notes).

comment:5 Changed 8 months ago by sergeykolosov

PR updated (compatibility with the latest master).

comment:6 Changed 7 months ago by berkerpeksag

  • Patch needs improvement set
  • Version changed from 1.6 to master

comment:7 Changed 2 months ago by sergeykolosov

  • Patch needs improvement unset

An new (updated) PR:

This one also addresses recent Django changes in models/migrations, namely not being able to import of an application which is not in INSTALLED_APPS.

comment:8 Changed 3 weeks ago by timgraham

  • Patch needs improvement set

Left some comments for improvement on the PR.

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