8000 [5.0.x] Fixed #35174 -- Fixed Signal.asend()/asend_robust() crash whe… · django/django@761e913 · GitHub
[go: up one dir, main page]

Skip to content

Commit 761e913

Browse files
illagrenanfelixxm
authored andcommitted
[5.0.x] Fixed #35174 -- Fixed Signal.asend()/asend_robust() crash when all receivers are asynchronous.
Regression in e83a885. Backport of 1b5338d from main
1 parent c22075a commit 761e913

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

django/dispatch/dispatcher.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ def sync_send():
244244
return responses
245245

246246
else:
247-
sync_send = list
247+
248+
async def sync_send():
249+
return []
248250

249251
responses, async_responses = await asyncio.gather(
250252
sync_send(),
@@ -380,7 +382,9 @@ def sync_send():
380382
return responses
381383

382384
else:
383-
sync_send = list
385+
386+
async def sync_send():
387+
return []
384388

385389
async def asend_and_wrap_exception(receiver):
386390
try:

docs/releases/5.0.3.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ Bugfixes
1111

1212
* Fixed a regression in Django 5.0.2 where ``intcomma`` template filter could
1313
return a leading comma for string representation of floats (:ticket:`35172`).
14+
15+
* Fixed a bug in Django 5.0 that caused a crash of ``Signal.asend()`` and
16+
``asend_robust()`` when all receivers were asynchronous functions
17+
(:ticket:`35174`).

tests/signals/tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,19 @@ async def failing_async_handler(**kwargs):
626626
(async_handler, 1),
627627
],
628628
)
629+
630+
async def test_asend_only_async_receivers(self):
631+
async_handler = AsyncHandler()
632+
signal = dispatch.Signal()
633+
signal.connect(async_handler)
634+
635+
result = await signal.asend(self.__class__)
636+
self.assertEqual(result, [(async_handler, 1)])
637+
638+
async def test_asend_robust_only_async_receivers(self):
639+
async_handler = AsyncHandler()
640+
signal = dispatch.Signal()
641+
signal.connect(async_handler)
642+
643+
result = await signal.asend_robust(self.__class__)
644+
self.assertEqual(result, [(async_handler, 1)])

0 commit comments

Comments
 (0)
0