[Django] #22634: Making Session model and SessionStore classes more easily extendable

31 views
Skip to first unread message

Django

unread,
May 16, 2014, 6:17:22 AM5/16/14
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
--------------------------------------+--------------------
Reporter: sergeykolosov | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.sessions | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
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 `models.py`,
`backends/db.py` and `backends/cached_db.py`.

The reason why one have to do that, is the way that `Session` model is
imported and used inside `backends/db.py` and `backends/cached_db.py`, and
the way `SessionStore` class imported and used inside `models.py`.

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).

--
Ticket URL: <https://code.djangoproject.com/ticket/22634>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 16, 2014, 6:29:10 AM5/16/14
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
--------------------------------------+------------------------------------

Reporter: sergeykolosov | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.sessions | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by russellm):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:1>

Django

unread,
May 16, 2014, 6:30:57 AM5/16/14
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sergeykolosov):

* status: new => assigned
* owner: nobody => sergeykolosov


--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:2>

Django

unread,
May 16, 2014, 12:43:54 PM5/16/14
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sergeykolosov):

* has_patch: 0 => 1


Comment:

Pull request: ​https://github.com/django/django/pull/2667

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:3>

Django

unread,
May 17, 2014, 11:19:22 AM5/17/14
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by sergeykolosov):

PR updated (documentation and release notes).

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:4>

Django

unread,
Dec 16, 2014, 1:23:17 PM12/16/14
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by sergeykolosov):

PR updated (compatibility with the latest master).

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:5>

Django

unread,
Dec 21, 2014, 11:26:50 AM12/21/14
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by berkerpeksag):

* needs_better_patch: 0 => 1
* version: 1.6 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:6>

Django

unread,
Jun 4, 2015, 9:03:02 AM6/4/15
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sergeykolosov):

* needs_better_patch: 1 => 0


Comment:

An new (updated) PR: https://github.com/django/django/pull/4754

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

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:7>

Django

unread,
Jul 8, 2015, 9:24:06 AM7/8/15
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

Left some comments for improvement on the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:8>

Django

unread,
Aug 11, 2015, 7:10:28 PM8/11/15
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sergeykolosov):

* needs_better_patch: 1 => 0


Comment:

PR updated: https://github.com/django/django/pull/4754

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:9>

Django

unread,
Aug 27, 2015, 9:53:46 AM8/27/15
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: assigned
Component: contrib.sessions | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:10>

Django

unread,
Aug 27, 2015, 3:03:57 PM8/27/15
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: closed
Component: contrib.sessions | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"22bb548900146832459deaefa880660c17a51516" 22bb5489]:
{{{
#!CommitTicketReference repository=""
revision="22bb548900146832459deaefa880660c17a51516"
Fixed #22634 -- Made the database-backed session backends more extensible.

Introduced an AbstractBaseSession model and hooks providing the option
of overriding the model class used by the session store and the session
store class used by the model.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:11>

Django

unread,
May 28, 2016, 5:33:30 PM5/28/16
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: closed
Component: contrib.sessions | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"cc0d1eaaea40dc9d784c6974be1ce631a2087c11" cc0d1eaa]:
{{{
#!CommitTicketReference repository=""
revision="cc0d1eaaea40dc9d784c6974be1ce631a2087c11"
Refs #22634 -- Removed unneeded app_label in custom session engine
example.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:12>

Django

unread,
May 28, 2016, 5:33:42 PM5/28/16
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: closed
Component: contrib.sessions | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"23e106bb721b3f4a41e40d9d98426e4cb2a12068" 23e106bb]:
{{{
#!CommitTicketReference repository=""
revision="23e106bb721b3f4a41e40d9d98426e4cb2a12068"
[1.10.x] Refs #22634 -- Removed unneeded app_label in custom session
engine example.

Backport of cc0d1eaaea40dc9d784c6974be1ce631a2087c11 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:13>

Django

unread,
May 28, 2016, 5:33:44 PM5/28/16
to django-...@googlegroups.com
#22634: Making Session model and SessionStore classes more easily extendable
-------------------------------------+-------------------------------------
Reporter: sergeykolosov | Owner:
Type: | sergeykolosov
Cleanup/optimization | Status: closed
Component: contrib.sessions | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"052f8499b9953e159e5b94c9afa2f243aa88ae39" 052f849]:
{{{
#!CommitTicketReference repository=""
revision="052f8499b9953e159e5b94c9afa2f243aa88ae39"
[1.9.x] Refs #22634 -- Removed unneeded app_label in custom session engine
example.

Backport of cc0d1eaaea40dc9d784c6974be1ce631a2087c11 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22634#comment:14>

Reply all
Reply to author
Forward
0 new messages