Skip to content

Commit 8926ef6

Browse files
check if async func and await
1 parent 45cf138 commit 8926ef6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

singlestoredb/functions/ext/asgi.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,17 @@ async def do_func(
319319
row_ids = array_cls(row_ids)
320320

321321
# Call the function with `cols` as the function parameters
322+
is_async = inspect.iscoroutinefunction(func) or inspect.iscoroutinefunction(getattr(func, "__wrapped__", None))
322323
if cols and cols[0]:
323-
out = func(*[x if m else x[0] for x, m in zip(cols, masks)])
324-
else:
325-
out = func()
326-
324+
if is_async:
325+
out = await func(*[x if m else x[0] for x, m in zip(cols, masks)])
326+
else:
327+
out = await asyncio.to_thread(func, *[x if m else x[0] for x, m in zip(cols, masks)])
328+
if is_async:
329+
out = await func()
330+
else:
331+
out = await asyncio.to_thread(func())
332+
327333
# Single masked value
328334
if isinstance(out, Masked):
329335
return row_ids, [tuple(out)]

0 commit comments

Comments
 (0)