#33578 closed New feature (invalid)
How feasible is modifying the django.db.connections object at run time for a multitenant system which uses isolated databases for tenancy
Reported by: | Mukil Rajeev | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.0 |
Severity: | Normal | Keywords: | dbrouter |
Cc: | mukilrajeev@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a FastAPI based application for which I am using the Django ORM to access the databases. And Im using the starlette-config dependency to manage the request context including the database details which will be part of the request.
I am currently updating the django.db.connections.databases object on the fly in a FastAPI middleware as detailed here: https://stackoverflow.com/a/28891429/2324527
After this, Im using a custom database router to select the newly added database for performing the database operation. Is this method feasible for production?
If so, do we have a more streamlined approach that could be introduced so that django supports dynamic database switching on the fly?
Change History (2)
comment:1 by , 3 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 3 years ago
Creating a new database connection or modifying an existing one on fly is not supported.
Trac is for bug reports only. Please see TicketClosingReasons/UseSupportChannels