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 = []
|
||||
for t in tasks:
|
||||
d = {}
|
||||
raw = vars(t) if hasattr(t, '__dict__') else {}
|
||||
for k, v in raw.items():
|
||||
if not callable(v) and not k.startswith('_'):
|
||||
if k == 'params' and v:
|
||||
try:
|
||||
p = json.loads(v) if isinstance(v, str) else v
|
||||
desc = p.get('description', '') or p.get('input_text', '') or ''
|
||||
d['description'] = desc[:60]
|
||||
except:
|
||||
d['description'] = ''
|
||||
elif k not in ('clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'to_dict'):
|
||||
v_str = str(v) if v is not None else ''
|
||||
d[k] = v_str
|
||||
# Use to_dict() if available (DictObject), otherwise vars()
|
||||
raw = {}
|
||||
if hasattr(t, 'to_dict') and callable(t.to_dict):
|
||||
try:
|
||||
raw = t.to_dict()
|
||||
except:
|
||||
pass
|
||||
if not raw and hasattr(t, '__dict__'):
|
||||
raw = vars(t)
|
||||
|
||||
# Extract fields directly
|
||||
for attr in ('id', 'title', 'state', 'current_version', 'created_at', 'role', 'params'):
|
||||
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)
|
||||
|
||||
return json.dumps({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user