summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/tasks/signals.py5
-rw-r--r--docs/releases/6.0.3.txt3
-rw-r--r--tests/tasks/test_immediate_backend.py9
3 files changed, 15 insertions, 2 deletions
diff --git a/django/tasks/signals.py b/django/tasks/signals.py
index 288fe08e32..919dae0222 100644
--- a/django/tasks/signals.py
+++ b/django/tasks/signals.py
@@ -49,6 +49,8 @@ def log_task_started(sender, task_result, **kwargs):
@receiver(task_finished)
def log_task_finished(sender, task_result, **kwargs):
+ # Signal is sent inside exception handlers, so exc_info() is available.
+ exc_info = sys.exc_info()
logger.log(
(
logging.ERROR
@@ -59,6 +61,5 @@ def log_task_finished(sender, task_result, **kwargs):
task_result.id,
task_result.task.module_path,
task_result.status,
- # Signal is sent inside exception handlers, so exc_info() is available.
- exc_info=sys.exc_info(),
+ exc_info=exc_info if exc_info[0] else None,
)
diff --git a/docs/releases/6.0.3.txt b/docs/releases/6.0.3.txt
index 3f8c93e63d..048921db8b 100644
--- a/docs/releases/6.0.3.txt
+++ b/docs/releases/6.0.3.txt
@@ -19,3 +19,6 @@ Bugfixes
* Fixed a visual regression where fieldset legends were misaligned in the admin
(:ticket:`36920`).
+
+* Prevented the :data:`django.tasks.signals.task_finished` signal from writing
+ extraneous log messages when no exceptions are encountered (:ticket:`36951`).
diff --git a/tests/tasks/test_immediate_backend.py b/tests/tasks/test_immediate_backend.py
index 356e9ab264..36b63faff8 100644
--- a/tests/tasks/test_immediate_backend.py
+++ b/tests/tasks/test_immediate_backend.py
@@ -228,6 +228,15 @@ class ImmediateBackendTestCase(SimpleTestCase):
self.assertIn("state=FAILED", captured_logs.output[2])
self.assertIn(result.id, captured_logs.output[2])
+ def test_successful_task_no_none_in_logs(self):
+ with self.assertLogs("django.tasks", level="DEBUG") as captured_logs:
+ result = test_tasks.noop_task.enqueue()
+
+ self.assertEqual(result.status, TaskResultStatus.SUCCESSFUL)
+
+ for log_output in captured_logs.output:
+ self.assertNotIn("None", log_output)
+
def test_takes_context(self):
result = test_tasks.get_task_id.enqueue()