fix: cockpit_project_tasks 所有查询放同一个 async with 块

This commit is contained in:
yumoqing 2026-08-07 17:12:13 +08:00
parent bcd160d38e
commit eb4f5ce017

View File

@ -9,7 +9,7 @@ if not uid:
dbname = get_module_dbname('pipeline-sdlc') dbname = get_module_dbname('pipeline-sdlc')
# Get current project from agent_settings # Get current project and tasks in one session
async with DBPools().sqlorContext(dbname) as sor: async with DBPools().sqlorContext(dbname) as sor:
recs = await sor.sqlExe( recs = await sor.sqlExe(
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${uid}$", "SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${uid}$",
@ -26,8 +26,7 @@ precs = await sor.sqlExe(
if precs and len(precs) > 0: if precs and len(precs) > 0:
pname = getattr(precs[0], 'name', '') or '' pname = getattr(precs[0], 'name', '') or ''
# Get tasks - filter by tenant_id matching project's org # Get tasks
# Use pipeline_task's DB or shared pipeline DB
tasks = await sor.sqlExe( tasks = await sor.sqlExe(
"SELECT id, title, state, current_version, created_at, params, role " "SELECT id, title, state, current_version, created_at, params, role "
"FROM pipeline_tasks WHERE tenant_id='0' ORDER BY created_at DESC LIMIT 50", "FROM pipeline_tasks WHERE tenant_id='0' ORDER BY created_at DESC LIMIT 50",
@ -36,11 +35,9 @@ tasks = await sor.sqlExe(
task_list = [] task_list = []
for t in tasks: for t in tasks:
d = {} d = {}
# Only copy real data fields, skip methods
raw = vars(t) if hasattr(t, '__dict__') else {} raw = vars(t) if hasattr(t, '__dict__') else {}
for k, v in raw.items(): for k, v in raw.items():
if not callable(v) and not k.startswith('_'): if not callable(v) and not k.startswith('_'):
# Extract short description from params JSON
if k == 'params' and v: if k == 'params' and v:
try: try:
p = json.loads(v) if isinstance(v, str) else v p = json.loads(v) if isinstance(v, str) else v