fix: wrap await task in try/except in async generator finally block

Addresses code quality review comment about bare 'await task' having
no visible effect. Now consistently handles CancelledError/Exception
in both the normal and cancellation paths of the finally block.

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2026-04-07 10:01:59 +00:00
parent 3702a47bfe
commit da65140cf8

View File

@@ -335,7 +335,10 @@ async def create_async_chunk_generator(
yield item
finally:
if not cancel_event.is_set():
await task
try:
await task
except (asyncio.CancelledError, Exception): # noqa: S110
pass
else:
if not task.done():
task.cancel()