[Django] #33578: How feasible is modifying the django.db.connections object at run time for a multitenant system which uses isolated databases for tenancy

8 views
Skip to first unread message

Django

unread,
Mar 15, 2022, 10:30:03 AM3/15/22
to django-...@googlegroups.com
#33578: How feasible is modifying the django.db.connections object at run time for
a multitenant system which uses isolated databases for tenancy
-------------------------------------+-------------------------------------
Reporter: mukilr | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: 4.0
layer (models, ORM) |
Severity: Normal | Keywords: dbrouter
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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?

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

Django

unread,
Mar 15, 2022, 10:47:04 AM3/15/22
to django-...@googlegroups.com
#33578: How feasible is modifying the django.db.connections object at run time for
a multitenant system which uses isolated databases for tenancy
-------------------------------------+-------------------------------------
Reporter: Mukil Rajeev | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: dbrouter | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => invalid


Comment:

Trac is for bug reports only. Please see
TicketClosingReasons/UseSupportChannels

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

Django

unread,
Mar 15, 2022, 10:48:15 AM3/15/22
to django-...@googlegroups.com
#33578: How feasible is modifying the django.db.connections object at run time for
a multitenant system which uses isolated databases for tenancy
-------------------------------------+-------------------------------------
Reporter: mukilr | Owner: nobody

Type: New feature | Status: closed
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: dbrouter | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Creating a new database connection or modifying an existing one on fly is
not supported.

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

Reply all
Reply to author
Forward
0 new messages