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 , 10 years ago
comment:2 by , 10 years ago
Cc: | added |
---|
comment:5 by , 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.
comment:6 by , 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 , 8 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
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.
In 3a85aae2eacae836e2a92de77615569883b81932: