Changes between Initial Version and Version 1 of Ticket #35349


Ignore:
Timestamp:
Apr 2, 2024, 6:14:40 AM (4 months ago)
Author:
Vitaliy Diachkov
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35349 – Description

    initial v1  
    1313
    1414
    15 The `atomic()`, `commit()` and other functions should get the write/transaction database under the hood.
     15The `atomic()`, `commit()` and other functions should access the write/transaction database under the hood.
    1616----
    1717** Note **: I am developing an application that switches the database connection on per-tenant bases. The database configurations are added to settings.DATABASES at runtime in a middleware and then, using the `contextvars.ContextVar` thread-local variable, I am passing the database alias to use from a middleware to my custom database router. It works fine for reading and writing data outside the transactions, but it fails when it comes to transaction. I could potentially pass the value of `ContextVar` as an argument to all Transaction API calls, but it still fails for the third-party libraries that are mostly calling this functions without arguments. I have patched globally `django.db.transaction.DEFAULT_DB_ALIAS` to a stub string-like object that resolves dynamically in a runtime to a value of `ContextVar`, but that solution seems to be weird and I wish I could make it through configuring `DATABASE_ROUTERS`.
Back to Top