From 85a9f33ac03239b91813a7c7edce701a327781bd Mon Sep 17 00:00:00 2001 From: Martijn Jacobs Date: Fri, 1 May 2020 17:29:27 +0200 Subject: [PATCH 1/2] Check for the right database when querying for get_autocommit --- django_q/brokers/orm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_q/brokers/orm.py b/django_q/brokers/orm.py index 911d5ba..008503a 100644 --- a/django_q/brokers/orm.py +++ b/django_q/brokers/orm.py @@ -17,7 +17,7 @@ def _timeout(): class ORM(Broker): @staticmethod def get_connection(list_key=Conf.PREFIX): - if transaction.get_autocommit(): # Only True when not in an atomic block + if transaction.get_autocommit(using=Conf.ORM): # Only True when not in an atomic block # Make sure stale connections in the broker thread are explicitly # closed before attempting DB access. # logger.debug("Broker thread calling close_old_connections") From f0546bc91cf2c961d58b9c15cbf5bad6487912df Mon Sep 17 00:00:00 2001 From: Martijn Jacobs Date: Fri, 1 May 2020 17:30:19 +0200 Subject: [PATCH 2/2] Lock the Scheduler model for the database it's using This can happen when you use a database router for example --- django_q/cluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index c6bffae..cb2877d 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -546,7 +546,7 @@ def scheduler(broker=None): broker = get_broker() close_old_django_connections() try: - with db.transaction.atomic(): + with db.transaction.atomic(using=Schedule.objects.db): for s in ( Schedule.objects.select_for_update() .exclude(repeats=0)