Skip to content

Commit

Permalink
Fixed #35174 -- Fixed Signal.asend()/asend_robust() crash when all re…
Browse files Browse the repository at this point in the history
…ceivers are asynchronous.

Regression in e83a885.
  • Loading branch information
illagrenan authored and felixxm committed Feb 8, 2024
1 parent 2f14c2c commit 1b5338d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions django/dispatch/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def sync_send():
return responses

else:
sync_send = list

async def sync_send():
return []

responses, async_responses = await asyncio.gather(
sync_send(),
Expand Down Expand Up @@ -380,7 +382,9 @@ def sync_send():
return responses

else:
sync_send = list

async def sync_send():
return []

async def asend_and_wrap_exception(receiver):
try:
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/5.0.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
16 changes: 16 additions & 0 deletions tests/signals/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,19 @@ async def failing_async_handler(**kwargs):
(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)])

0 comments on commit 1b5338d

Please sign in to comment.