Skip to content

Commit 2610ec6

Browse files
committed
fix: forgot to await system task wrapper
1 parent d43ba14 commit 2610ec6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

silverback/main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import inspect
33
from collections import defaultdict
44
from datetime import timedelta
5-
from functools import update_wrapper, wraps
5+
from functools import wraps
66
from typing import Any, Awaitable, Callable
77

88
from ape.api.networks import LOCAL_NETWORK_NAME
@@ -180,11 +180,21 @@ def __register_system_task(
180180
self, task_type: TaskType, task_handler: Callable
181181
) -> AsyncTaskiqDecoratedTask:
182182
assert str(task_type).startswith("system:"), "Can only add system tasks"
183+
184+
# NOTE: We need this as `.register_task` tries to update `.__name__` of `task_handler`,
185+
# but methods do not allow setting this attribute (raises AttributeError)
186+
@wraps(task_handler)
187+
async def call_task_handler(*args, **kwargs):
188+
result = task_handler(*args, **kwargs)
189+
190+
if inspect.isawaitable(result):
191+
return await result
192+
193+
return result
194+
183195
# NOTE: This has to be registered with the broker in the worker
184196
return self.broker.register_task(
185-
# NOTE: We need this as `.register_task` tries to update `.__name__` of `task_handler`,
186-
# but it is a method not a function (`update_wrapper` transforms it into one)
187-
update_wrapper(lambda *args, **kwargs: task_handler(*args, **kwargs), task_handler),
197+
call_task_handler,
188198
# NOTE: Name makes it impossible to conflict with user's handler fn names
189199
task_name=str(task_type),
190200
task_type=str(task_type),

0 commit comments

Comments
 (0)