summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/dispatch/dispatcher.py8
-rw-r--r--docs/releases/5.0.3.txt4
-rw-r--r--tests/signals/tests.py16
3 files changed, 26 insertions, 2 deletions
diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
index 26ef09ce49..fe0e1fa599 100644
--- a/django/dispatch/dispatcher.py
+++ b/django/dispatch/dispatcher.py
@@ -244,7 +244,9 @@ class Signal:
return responses
else:
- sync_send = list
+
+ async def sync_send():
+ return []
responses, async_responses = await asyncio.gather(
sync_send(),
@@ -380,7 +382,9 @@ class Signal:
return responses
else:
- sync_send = list
+
+ async def sync_send():
+ return []
async def asend_and_wrap_exception(receiver):
try:
diff --git a/docs/releases/5.0.3.txt b/docs/releases/5.0.3.txt
index 384ce27fb7..30e87127b0 100644
--- a/docs/releases/5.0.3.txt
+++ b/docs/releases/5.0.3.txt
@@ -11,3 +11,7 @@ Bugfixes
* Fixed a regression in Django 5.0.2 where ``intcomma`` template filter could
return a leading comma for string representation of floats (:ticket:`35172`).
+
+* Fixed a bug in Django 5.0 that caused a crash of ``Signal.asend()`` and
+ ``asend_robust()`` when all receivers were asynchronous functions
+ (:ticket:`35174`).
diff --git a/tests/signals/tests.py b/tests/signals/tests.py
index 5558778bbe..6c90c6aa52 100644
--- a/tests/signals/tests.py
+++ b/tests/signals/tests.py
@@ -626,3 +626,19 @@ class AsyncReceiversTests(SimpleTestCase):
(async_handler, 1),
],
)
+
+ async def test_asend_only_async_receivers(self):
+ async_handler = AsyncHandler()
+ signal = dispatch.Signal()
+ signal.connect(async_handler)
+
+ result = await signal.asend(self.__class__)
+ self.assertEqual(result, [(async_handler, 1)])
+
+ async def test_asend_robust_only_async_receivers(self):
+ async_handler = AsyncHandler()
+ signal = dispatch.Signal()
+ signal.connect(async_handler)
+
+ result = await signal.asend_robust(self.__class__)
+ self.assertEqual(result, [(async_handler, 1)])