Opened 10 years ago

Closed 8 years ago

#22986 closed New feature (worksforme)

Allow disabling session model database table creation if not used by session engine

Reported by: Tim Graham Owned by: nobody
Component: contrib.sessions Version: dev
Severity: Normal Keywords:
Cc: chris.jerdonek@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Previously, we recommended removing contrib.sessions from INSTALLED_APPS but this causes the test client login to break (#22934) and also disables the clearsessions management command which could be useful for the file-based sessions (which also don't require the database tables).

Change History (7)

comment:1 by Tim Graham <timograham@…>, 10 years ago

In 3a85aae2eacae836e2a92de77615569883b81932:

Revert "Improve cookie based session backend docs." refs #20418

This reverts commit d9c01da1f8ba3d4e0947fd1d619c8f4a9b013360.

This is poor advice as it breaks the test client login (refs #22934).
We can add a note like this back after refs #22986 is resolved.

comment:2 by Chris Jerdonek, 10 years ago

Cc: chris.jerdonek@… added

comment:3 by Tim Graham <timograham@…>, 10 years ago

In a3d710a38f1fab5e092cef7a17826674a00e70ea:

[1.7.x] Revert "Improve cookie based session backend docs." refs #20418

This reverts commit d9c01da1f8ba3d4e0947fd1d619c8f4a9b013360.

This is poor advice as it breaks the test client login (refs #22934).
We can add a note like this back after refs #22986 is resolved.

Backport of 3a85aae2ea from master

comment:4 by Tim Graham <timograham@…>, 10 years ago

In f3bdb83ba58a696c0696d8a6706d2c44a00da68a:

[1.6.x] Revert "Improve cookie based session backend docs." refs #20418

This reverts commit d9c01da1f8ba3d4e0947fd1d619c8f4a9b013360.

This is poor advice as it breaks the test client login (refs #22934).
We can add a note like this back after refs #22986 is resolved.

Backport of 3a85aae2ea from master

comment:5 by Nick Sandford, 10 years ago

Has patch: set
Needs documentation: set
Needs tests: set
Patch needs improvement: set

I was going to tackle this, and thought that maybe we could abuse _meta.swappable, but it appears that ModelBase._check_swappable actually checks that the swappable model exists.

I wonder if this would be a use-case for the app registry to allow unregistering models? Then in the session app config's ready() we could conditionally unregister the Session model if the session engine doesn't require it.

My approach was to override AppConfig.get_model and AppConfig.get_models as a way to "disable" the session model. Unfortunately this doesn't work for migrations.

PR here: https://github.com/django/django/pull/2960

comment:6 by Chris Jerdonek, 10 years ago

I haven't looked into the history of this, but it seems like one of the issues is that INSTALLED_APPS is currently being used for two different but related purposes: 1) to say which apps are being used, and 2) to say what models need to be added to the schema. I wonder what would be the best way to make this distinction.

comment:7 by Aymeric Augustin, 8 years ago

Resolution: worksforme
Status: newclosed

Since Django 1.7 we have a clean way to prevent the creation of database tables, which is the crux of the issue here:

MIGRATION_MODULES = {
    'sessions': None
}

On one hand, it's a slightly convoluted way to declare that you aren't using the Session model. On the other hand, it's a reasonable way to tell Django not to run migrations that create the table backing the Session model.

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