From 230033f350e9f4545dcaa7279d413a7acabe8e52 Mon Sep 17 00:00:00 2001 From: Kaushik Kampli Date: Thu, 26 Jun 2025 11:05:37 +0530 Subject: [PATCH] check if async func and await --- singlestoredb/functions/ext/asgi.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/singlestoredb/functions/ext/asgi.py b/singlestoredb/functions/ext/asgi.py index c8ff8f4f5..ed29de846 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)]