summaryrefslogtreecommitdiff
path: root/django/tasks
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-09-17 09:19:25 -0400
committernessita <124304+nessita@users.noreply.github.com>2025-09-17 13:28:58 -0300
commitb931156c207f661406635d49e0e29a51cacc1ab8 (patch)
tree4d9adccade76009e4d7e6c9927ec08eb8790b0b6 /django/tasks
parent9334499f537e402ce5b92708209933045a8c5e7d (diff)
Refs #35859 -- Removed support for Task enqueuing on transaction commit.
This removes the ability to configure Task enqueueing via a setting, since the proposed `ENQUEUE_ON_COMMIT` did not support multi-database setups. Thanks to Simon Charette for the report. Follow-up to 4289966d1b8e848e5e460b7c782dac009d746b20.
Diffstat (limited to 'django/tasks')
-rw-r--r--django/tasks/backends/base.py28
-rw-r--r--django/tasks/backends/dummy.py7
-rw-r--r--django/tasks/backends/immediate.py7
-rw-r--r--django/tasks/base.py6
4 files changed, 3 insertions, 45 deletions
diff --git a/django/tasks/backends/base.py b/django/tasks/backends/base.py
index 32ae10018d..938e36f21e 100644
--- a/django/tasks/backends/base.py
+++ b/django/tasks/backends/base.py
@@ -4,8 +4,6 @@ from inspect import iscoroutinefunction
from asgiref.sync import sync_to_async
from django.conf import settings
-from django.core import checks
-from django.db import connections
from django.tasks import DEFAULT_TASK_QUEUE_NAME
from django.tasks.base import (
DEFAULT_TASK_PRIORITY,
@@ -39,16 +37,8 @@ class BaseTaskBackend(metaclass=ABCMeta):
def __init__(self, alias, params):
self.alias = alias
self.queues = set(params.get("QUEUES", [DEFAULT_TASK_QUEUE_NAME]))
- self.enqueue_on_commit = bool(params.get("ENQUEUE_ON_COMMIT", True))
self.options = params.get("OPTIONS", {})
- def _get_enqueue_on_commit_for_task(self, task):
- return (
- task.enqueue_on_commit
- if task.enqueue_on_commit is not None
- else self.enqueue_on_commit
- )
-
def validate_task(self, task):
"""
Determine whether the provided Task can be executed by the backend.
@@ -119,20 +109,4 @@ class BaseTaskBackend(metaclass=ABCMeta):
)
def check(self, **kwargs):
- if self.enqueue_on_commit and not connections._settings:
- yield checks.Error(
- "ENQUEUE_ON_COMMIT cannot be used when no databases are configured.",
- hint="Set ENQUEUE_ON_COMMIT to False",
- id="tasks.E001",
- )
-
- elif (
- self.enqueue_on_commit
- and not connections["default"].features.supports_transactions
- ):
- yield checks.Error(
- "ENQUEUE_ON_COMMIT cannot be used on a database which doesn't support "
- "transactions.",
- hint="Set ENQUEUE_ON_COMMIT to False",
- id="tasks.E002",
- )
+ return []
diff --git a/django/tasks/backends/dummy.py b/django/tasks/backends/dummy.py
index 93bb8f3ee4..bc7060ccc4 100644
--- a/django/tasks/backends/dummy.py
+++ b/django/tasks/backends/dummy.py
@@ -1,7 +1,5 @@
from copy import deepcopy
-from functools import partial
-from django.db import transaction
from django.tasks.base import TaskResult, TaskResultStatus
from django.tasks.exceptions import TaskResultDoesNotExist
from django.tasks.signals import task_enqueued
@@ -43,10 +41,7 @@ class DummyBackend(BaseTaskBackend):
worker_ids=[],
)
- if self._get_enqueue_on_commit_for_task(task) is not False:
- transaction.on_commit(partial(self._store_result, result))
- else:
- self._store_result(result)
+ self._store_result(result)
# Copy the task to prevent mutation issues.
return deepcopy(result)
diff --git a/django/tasks/backends/immediate.py b/django/tasks/backends/immediate.py
index 06b94d18ab..2e154850aa 100644
--- a/django/tasks/backends/immediate.py
+++ b/django/tasks/backends/immediate.py
@@ -1,8 +1,6 @@
import logging
-from functools import partial
from traceback import format_exception
-from django.db import transaction
from django.tasks.base import TaskContext, TaskError, TaskResult, TaskResultStatus
from django.tasks.signals import task_enqueued, task_finished, task_started
from django.utils import timezone
@@ -92,9 +90,6 @@ class ImmediateBackend(BaseTaskBackend):
worker_ids=[],
)
- if self._get_enqueue_on_commit_for_task(task) is not False:
- transaction.on_commit(partial(self._execute_task, task_result))
- else:
- self._execute_task(task_result)
+ self._execute_task(task_result)
return task_result
diff --git a/django/tasks/base.py b/django/tasks/base.py
index 905dbef597..cffcdd8996 100644
--- a/django/tasks/base.py
+++ b/django/tasks/base.py
@@ -48,10 +48,6 @@ class Task:
queue_name: str
run_after: Optional[datetime] # The earliest this Task will run.
- # Whether the Task will be enqueued when the current transaction commits,
- # immediately, or whatever the backend decides.
- enqueue_on_commit: Optional[bool]
-
# Whether the Task receives the Task context when executed.
takes_context: bool = False
@@ -140,7 +136,6 @@ def task(
priority=DEFAULT_TASK_PRIORITY,
queue_name=DEFAULT_TASK_QUEUE_NAME,
backend=DEFAULT_TASK_BACKEND_ALIAS,
- enqueue_on_commit=None,
takes_context=False,
):
from . import task_backends
@@ -151,7 +146,6 @@ def task(
func=f,
queue_name=queue_name,
backend=backend,
- enqueue_on_commit=enqueue_on_commit,
takes_context=takes_context,
run_after=None,
)