🐛 Fix: 修复结构化并发子依赖取消缓存问题 (#3084)

This commit is contained in:
Ju4tCode
2024-10-29 14:22:41 +08:00
committed by GitHub
parent be732cf9d8
commit e3cb4c7907
4 changed files with 69 additions and 5 deletions

View File

@ -21,7 +21,12 @@ from nonebot.log import logger
from nonebot.typing import _DependentCallable
from nonebot.exception import SkippedException
from nonebot.compat import FieldInfo, ModelField, PydanticUndefined
from nonebot.utils import run_sync, is_coroutine_callable, flatten_exception_group
from nonebot.utils import (
run_sync,
run_coro_with_shield,
is_coroutine_callable,
flatten_exception_group,
)
from .utils import check_field_type, get_typed_signature
@ -207,7 +212,10 @@ class Dependent(Generic[R]):
async with anyio.create_task_group() as tg:
for field in self.params:
tg.start_soon(_solve_field, field, params)
# shield the task to prevent cancellation
# when one of the tasks raises an exception
# this will improve the dependency cache reusability
tg.start_soon(run_coro_with_shield, _solve_field(field, params))
return result