@@ -38,9 +38,9 @@ async def get_datasource(session: SessionDep, id: int):
3838
3939
4040@router .post ("/check" )
41- async def check (session : SessionDep , ds : CoreDatasource ):
41+ async def check (session : SessionDep , trans : Trans , ds : CoreDatasource ):
4242 def inner ():
43- return check_status (session , ds , True )
43+ return check_status (session , trans , ds , True )
4444
4545 return await asyncio .to_thread (inner )
4646
@@ -54,9 +54,9 @@ def inner():
5454
5555
5656@router .post ("/chooseTables/{id}" )
57- async def choose_tables (session : SessionDep , id : int , tables : List [CoreTable ]):
57+ async def choose_tables (session : SessionDep , trans : Trans , id : int , tables : List [CoreTable ]):
5858 def inner ():
59- chooseTables (session , id , tables )
59+ chooseTables (session , trans , id , tables )
6060
6161 await asyncio .to_thread (inner )
6262
@@ -80,12 +80,18 @@ async def get_tables(session: SessionDep, id: int):
8080
8181
8282@router .post ("/getTablesByConf" )
83- async def get_tables_by_conf (session : SessionDep , ds : CoreDatasource ):
83+ async def get_tables_by_conf (session : SessionDep , trans : Trans , ds : CoreDatasource ):
8484 try :
8585 return getTablesByDs (session , ds )
8686 except Exception as e :
87- SQLBotLogUtil .error (f"get table failed: { e } " )
88- raise HTTPException (status_code = 500 , detail = f'Get table Failed: { e .args } ' )
87+ # check ds status
88+ def inner ():
89+ return check_status (session , trans , ds , True )
90+
91+ status = await asyncio .to_thread (inner )
92+ if status :
93+ SQLBotLogUtil .error (f"get table failed: { e } " )
94+ raise HTTPException (status_code = 500 , detail = f'Get table Failed: { e .args } ' )
8995
9096
9197@router .post ("/getFields/{id}/{table_name}" )
@@ -127,13 +133,17 @@ async def edit_field(session: SessionDep, field: CoreField):
127133
128134
129135@router .post ("/previewData/{id}" )
130- async def preview_data (session : SessionDep , current_user : CurrentUser , id : int , data : TableObj ):
136+ async def preview_data (session : SessionDep , trans : Trans , current_user : CurrentUser , id : int , data : TableObj ):
131137 def inner ():
132138 try :
133139 return preview (session , current_user , id , data )
134140 except Exception as e :
135- SQLBotLogUtil .error (f"Preview failed: { e } " )
136- raise HTTPException (status_code = 500 , detail = f'Preview Failed: { e .args } ' )
141+ ds = session .query (CoreDatasource ).filter (CoreDatasource .id == id ).first ()
142+ # check ds status
143+ status = check_status (session , trans , ds , True )
144+ if status :
145+ SQLBotLogUtil .error (f"Preview failed: { e } " )
146+ raise HTTPException (status_code = 500 , detail = f'Preview Failed: { e .args } ' )
137147
138148 return await asyncio .to_thread (inner )
139149
@@ -195,7 +205,8 @@ def inner():
195205 create_table (conn , tableName , fields )
196206
197207 data = [
198- {df .columns [i ]: None if pd .isna (row [i ]) else (int (row [i ]) if "int" in str (df .dtypes [i ]) else row [i ])
208+ {df .columns [i ]: None if pd .isna (row [i ]) else (
209+ int (row [i ]) if "int" in str (df .dtypes [i ]) else row [i ])
199210 for i in range (len (row ))}
200211 for row in df .values
201212 ]
0 commit comments