fix: 直接用getattr取DictObject字段
This commit is contained in:
parent
eb4f5ce017
commit
b0bf86dc66
@ -35,19 +35,34 @@ async with DBPools().sqlorContext(dbname) as sor:
|
|||||||
task_list = []
|
task_list = []
|
||||||
for t in tasks:
|
for t in tasks:
|
||||||
d = {}
|
d = {}
|
||||||
raw = vars(t) if hasattr(t, '__dict__') else {}
|
# Use to_dict() if available (DictObject), otherwise vars()
|
||||||
for k, v in raw.items():
|
raw = {}
|
||||||
if not callable(v) and not k.startswith('_'):
|
if hasattr(t, 'to_dict') and callable(t.to_dict):
|
||||||
if k == 'params' and v:
|
try:
|
||||||
try:
|
raw = t.to_dict()
|
||||||
p = json.loads(v) if isinstance(v, str) else v
|
except:
|
||||||
desc = p.get('description', '') or p.get('input_text', '') or ''
|
pass
|
||||||
d['description'] = desc[:60]
|
if not raw and hasattr(t, '__dict__'):
|
||||||
except:
|
raw = vars(t)
|
||||||
d['description'] = ''
|
|
||||||
elif k not in ('clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'to_dict'):
|
# Extract fields directly
|
||||||
v_str = str(v) if v is not None else ''
|
for attr in ('id', 'title', 'state', 'current_version', 'created_at', 'role', 'params'):
|
||||||
d[k] = v_str
|
val = getattr(t, attr, '') or ''
|
||||||
|
if attr == 'params' and val:
|
||||||
|
try:
|
||||||
|
p = json.loads(val) if isinstance(val, str) else val
|
||||||
|
d['description'] = p.get('description', '') or p.get('input_text', '') or ''
|
||||||
|
except:
|
||||||
|
d['description'] = ''
|
||||||
|
elif attr == 'created_at':
|
||||||
|
d[attr] = str(val)[:16] if val else ''
|
||||||
|
elif attr == 'current_version':
|
||||||
|
d[attr] = str(val) if val is not None else '1'
|
||||||
|
else:
|
||||||
|
d[attr] = str(val) if val else ''
|
||||||
|
|
||||||
|
if not d.get('title'):
|
||||||
|
continue
|
||||||
task_list.append(d)
|
task_list.append(d)
|
||||||
|
|
||||||
return json.dumps({
|
return json.dumps({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user