From 7abf09c389d5976a8bca33d4d7ac0476d4e664d6 Mon Sep 17 00:00:00 2001 From: pipeline-agent Date: Sun, 30 Aug 2026 08:46:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20sqlorContext=E5=BF=85=E9=A1=BB=E8=B5=B0D?= =?UTF-8?q?BPools=E2=80=94=E2=80=94ServerEnv(DictObject)=E7=BC=BA=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=BF=94=E5=9B=9ENone=E5=AF=BC=E8=87=B4=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=94=BB=E5=B8=83CRUD=E6=8A=A5NoneType=20not=20callab?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scense_drag/init.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/scense_drag/init.py b/scense_drag/init.py index 1be2747..c45d304 100644 --- a/scense_drag/init.py +++ b/scense_drag/init.py @@ -42,6 +42,12 @@ def _dumps(obj): return json.dumps(obj, ensure_ascii=False) +def _sqlor_ctx(dbname): + """取 sqlor 连接上下文(必须用 DBPools,ServerEnv 无 sqlorContext)。""" + from sqlor.dbpools import DBPools + return DBPools().sqlorContext(dbname) + + async def get_drag_graph_dbname(): """drag 业务库名(宿主 get_module_dbname 决定)。""" try: @@ -64,7 +70,7 @@ async def list_drag_graphs(params=None): params = params or {} dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: where, args = [], [] name = params.get('name') status = params.get('status') @@ -97,7 +103,7 @@ async def get_drag_graph(ns): return {'code': 'PARAM_REQUIRED', 'message': '缺少 id', 'field': 'id'} dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: recs = await sor.R('drag_graph', {'id': gid}) if not recs: return {'code': 'NOT_FOUND', 'message': '画布不存在: %s' % gid} @@ -149,7 +155,7 @@ async def create_drag_graph(ns): content = result.get('content', '') if result.get('success') else '' dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: await sor.C('drag_graph', { 'id': gid, 'name': str(name).strip(), 'description': str(ns.get('description') or ''), @@ -189,7 +195,7 @@ async def update_drag_graph(ns): content = result.get('content', '') if result.get('success') else '' dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: recs = await sor.R('drag_graph', {'id': gid}) if not recs: return {'code': 'NOT_FOUND', 'message': '画布不存在: %s' % gid} @@ -215,7 +221,7 @@ async def delete_drag_graph(ns): return {'code': 'PARAM_REQUIRED', 'message': '缺少 id', 'field': 'id'} dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: await sor.D('drag_graph', {'id': gid}) return {'success': True, 'id': gid} except Exception as e: @@ -315,7 +321,7 @@ async def list_drag_templates(params=None): params = params or {} dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: where, args = [], [] name = params.get('name') if name: @@ -344,7 +350,7 @@ async def get_drag_template(ns): return {'code': 'PARAM_REQUIRED', 'message': '缺少 id', 'field': 'id'} dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: recs = await sor.R('drag_template', {'id': tid}) if not recs: return {'code': 'NOT_FOUND', 'message': '模板不存在: %s' % tid} @@ -384,7 +390,7 @@ async def create_drag_template(ns): v = validate_graph({'blocks': blocks, 'connections': conns}) dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: tid = _new_id() await sor.C('drag_template', { 'id': tid, 'name': str(name).strip(), @@ -416,7 +422,7 @@ async def update_drag_template(ns): return {'code': 'PARAM_TYPE', 'message': 'connections 不是合法 JSON', 'field': 'connections'} dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: recs = await sor.R('drag_template', {'id': tid}) if not recs: return {'code': 'NOT_FOUND', 'message': '模板不存在: %s' % tid} @@ -444,7 +450,7 @@ async def delete_drag_template(ns): return {'code': 'PARAM_REQUIRED', 'message': '缺少 id', 'field': 'id'} dbname = await get_drag_graph_dbname() try: - async with _server_env().sqlorContext(dbname) as sor: + async with _sqlor_ctx(dbname) as sor: await sor.D('drag_template', {'id': tid}) return {'success': True, 'id': tid} except Exception as e: