Skip to content

Commit 5a282aa

Browse files
Merge branch 'main' of https://github.com/singlestore-labs/singlestoredb-python into users/kaushik/udf-idle-start-fix
2 parents 459d8ab + 93a0018 commit 5a282aa

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

singlestoredb/apps/_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from dataclasses import dataclass
33
from typing import Optional
4+
from singlestoredb.connection import build_params
45

56

67
@dataclass
@@ -9,6 +10,8 @@ class AppConfig:
910
base_url: str
1011
base_path: str
1112
notebook_server_id: str
13+
workspace_group_id: str
14+
database_name: str
1215
app_token: Optional[str]
1316
user_token: Optional[str]
1417
running_interactively: bool
@@ -41,6 +44,15 @@ def from_env(cls) -> 'AppConfig':
4144
app_token = os.environ.get('SINGLESTOREDB_APP_TOKEN')
4245
user_token = os.environ.get('SINGLESTOREDB_USER_TOKEN')
4346

47+
if 'SINGLESTOREDB_URL' in os.environ:
48+
dbname = build_params(host=os.environ['SINGLESTOREDB_URL']).get('database')
49+
elif 'SINGLESTOREDB_HOST' in os.environ:
50+
dbname = build_params(host=os.environ['SINGLESTOREDB_HOST']).get('database')
51+
elif 'SINGLESTOREDB_DATABASE' in os.environ:
52+
dbname = os.environ['SINGLESTOREDB_DATBASE']
53+
54+
workspace_group_id = os.environ.get('SINGLESTOREDB_WORKSPACE_GROUP')
55+
4456
# Make sure the required variables are present
4557
# and present useful error message if not
4658
if running_interactively:
@@ -54,6 +66,8 @@ def from_env(cls) -> 'AppConfig':
5466
base_url=base_url,
5567
base_path=base_path,
5668
notebook_server_id=notebook_server_id,
69+
workspace_group_id=workspace_group_id,
70+
database_name=dbname,
5771
app_token=app_token,
5872
user_token=user_token,
5973
running_interactively=running_interactively,

singlestoredb/apps/_python_udfs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ._config import AppConfig
77
from ._connection_info import UdfConnectionInfo
88
from ._process import kill_process_by_port
9+
from singlestoredb.connection import build_params
910

1011
if typing.TYPE_CHECKING:
1112
from ._uvicorn_util import AwaitableUvicornServer
@@ -43,7 +44,7 @@ async def run_udf_app(
4344

4445
udf_suffix = ''
4546
if app_config.running_interactively:
46-
udf_suffix = '_test'
47+
udf_suffix = "_" + app_config.notebook_server_id
4748
app = Application(url=base_url, app_mode='managed', name_suffix=udf_suffix)
4849

4950
config = uvicorn.Config(

singlestoredb/functions/ext/asgi.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from typing import Set
5454
from typing import Tuple
5555
from typing import Union
56+
from ...apps._config import AppConfig
5657

5758
from . import arrow
5859
from . import json as jdata
@@ -67,8 +68,6 @@
6768
from ..typing import Masked
6869
from ..typing import Table
6970
from ...config import get_option
70-
from singlestoredb.connection import build_params
71-
7271

7372
try:
7473
import cloudpickle
@@ -905,8 +904,18 @@ async def __call__(
905904

906905
# Return function info
907906
elif method == 'GET' and (path == self.show_function_info_path or not path):
907+
app_config = AppConfig.from_env()
908908
functions = self.get_function_info()
909-
body = json.dumps(dict(functions=functions)).encode('utf-8')
909+
workspace = app_config.workspace_group_id
910+
database = app_config.database_name
911+
912+
body = json.dumps({
913+
"functions": functions,
914+
"cluster_id": workspace,
915+
"database": database,
916+
}).encode('utf-8')
917+
918+
print(body)
910919
await send(self.text_response_dict)
911920

912921
# Path not found
@@ -981,18 +990,7 @@ def get_function_info(
981990
sig = info['signature']
982991
sql_map[sig['name']] = sql
983992

984-
if 'SINGLESTOREDB_URL' in os.environ:
985-
dbname = build_params(host=os.environ['SINGLESTOREDB_URL']).get('database')
986-
elif 'SINGLESTOREDB_HOST' in os.environ:
987-
dbname = build_params(host=os.environ['SINGLESTOREDB_HOST']).get('database')
988-
elif 'SINGLESTOREDB_DATABASE' in os.environ:
989-
dbname = os.environ['SINGLESTOREDB_DATBASE']
990993

991-
connection_info = {}
992-
workspace_group_id = os.environ.get('SINGLESTOREDB_WORKSPACE_GROUP')
993-
connection_info['database_name'] = dbname
994-
connection_info['workspace_group_id'] = workspace_group_id
995-
996994

997995
for key, (_, info) in self.endpoints.items():
998996
if not func_name or key == func_name:
@@ -1039,10 +1037,7 @@ def get_function_info(
10391037
sql_statement=sql,
10401038
)
10411039

1042-
return {
1043-
'functions': functions,
1044-
'connection_info': connection_info
1045-
}
1040+
return functions
10461041

10471042
def get_create_functions(
10481043
self,

0 commit comments

Comments
 (0)