-
Notifications
You must be signed in to change notification settings - Fork 97
Open
Description
Problems
In my project, i have some serveral databases. so, my settings.py looks like below.
# settings.py
DATABASES = {
"default": {
...
},
"sales": {
...
},
...
}When i set on_commit=True and operated with some objects of sales, it failed.
And i find we call transaction.on_commit
# mixins.py
class OnCommitHookedMethod(AbstractHookedMethod):
""" Hooked method that should run on_commit """
@property
def name(self) -> str:
# Append `_on_commit` to the existing method name to allow for firing
# the same hook within the atomic transaction and on_commit
return f"{self.method.__name__}_on_commit"
def run(self, instance: Any) -> None:
# Use partial to create a function closure that binds `self`
# to ensure it's available to execute later.
_on_commit_func = partial(self.method, instance)
_on_commit_func.__name__ = self.name
# Can we allow passing using param here? Or, get using from instance directly
transaction.on_commit(_on_commit_func)
# django/db/transaction.py
def get_connection(using=None):
"""
Get a database connection by name, or the default database connection
if no name is provided. This is a private API.
"""
if using is None: # here!
using = DEFAULT_DB_ALIAS
return connections[using]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels