Skip to content

Commit fbdbc66

Browse files
committed
fix: Fix the data source-related issues in the PR
1 parent 33c6b7b commit fbdbc66

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

backend/apps/db/db.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,17 @@ def check_connection(trans: Optional[Trans], ds: CoreDatasource | AssistantOutDs
256256
raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid') + f': {e.args}')
257257
return False
258258
elif equals_ignore_case(ds.type, 'hive'):
259-
try:
260-
conn = hive.connect(host=conf.host, port=conf.port, username=conf.username,
261-
database=conf.database, **extra_config_dict)
262-
cursor = conn.cursor()
263-
cursor.execute('select 1')
264-
cursor.fetchall()
265-
cursor.close()
266-
conn.close()
267-
SQLBotLogUtil.info("success")
268-
return True
269-
except Exception as e:
270-
SQLBotLogUtil.error(f"Datasource {ds.id} connection failed: {e}")
271-
if is_raise:
272-
raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid') + f': {e.args}')
273-
return False
259+
with hive.connect(host=conf.host, port=conf.port, username=conf.username,
260+
database=conf.database, **extra_config_dict) as conn, conn.cursor() as cursor:
261+
try:
262+
cursor.execute('select 1')
263+
SQLBotLogUtil.info("success")
264+
return True
265+
except Exception as e:
266+
SQLBotLogUtil.error(f"Datasource {ds.id} connection failed: {e}")
267+
if is_raise:
268+
raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid') + f': {e.args}')
269+
return False
274270

275271
elif equals_ignore_case(ds.type, 'es'):
276272
es_conn = get_es_connect(conf)

0 commit comments

Comments
 (0)