diff --git a/singlestoredb/functions/ext/asgi.py b/singlestoredb/functions/ext/asgi.py index 97997ffc9..1f2f42c49 100755 --- a/singlestoredb/functions/ext/asgi.py +++ b/singlestoredb/functions/ext/asgi.py @@ -319,11 +319,18 @@ async def do_func( row_ids = array_cls(row_ids) # Call the function with `cols` as the function parameters + is_async = inspect.iscoroutinefunction(func) or inspect.iscoroutinefunction(getattr(func, "__wrapped__", None)) if cols and cols[0]: - out = func(*[x if m else x[0] for x, m in zip(cols, masks)]) + if is_async: + out = await func(*[x if m else x[0] for x, m in zip(cols, masks)]) + else: + out = await asyncio.to_thread(func, *[x if m else x[0] for x, m in zip(cols, masks)]) else: - out = func() - + if is_async: + out = await func() + else: + out = await asyncio.to_thread(func()) + # Single masked value if isinstance(out, Masked): return row_ids, [tuple(out)]