diff --git a/pipeline_service/communication.py b/pipeline_service/communication.py index 7b21559..e07e4bf 100644 --- a/pipeline_service/communication.py +++ b/pipeline_service/communication.py @@ -177,10 +177,22 @@ async def list_problems_for(role, agentid=None, tenant_id=None, task_id=None, li def _rec_to_dict(rec): - if hasattr(rec, '__dict__'): - return {k: getattr(rec, k) for k in dir(rec) - if not k.startswith('_') and not callable(getattr(rec, k))} - return dict(rec) + """把 sqlor 记录对象转成 dict。 + + sqlor 返回 appPublic.dictObject.DictObject,列名不暴露为实例属性(dir() 只列 dict 方法), + 必须用 dict(rec) 取列,不能用 dir(rec) + getattr(会取到 None/方法)。 + """ + if isinstance(rec, dict): + return dict(rec) + try: + return dict(rec) + except (TypeError, ValueError): + if hasattr(rec, 'to_dict'): + try: + return rec.to_dict() + except Exception: + pass + return {} async def get_task_qa(task_id, role=None, agentid=None) -> dict: diff --git a/pipeline_service/questions.py b/pipeline_service/questions.py index 4e7a7c7..7e9aa18 100644 --- a/pipeline_service/questions.py +++ b/pipeline_service/questions.py @@ -71,10 +71,10 @@ async def get_question(question_id: str): if not recs: return None rec = recs[0] - if hasattr(rec, '__dict__'): - d = {k: getattr(rec, k) for k in dir(rec) if not k.startswith('_')} - else: + try: d = dict(rec) + except Exception: + d = {} ctx = d.get('context') if ctx and isinstance(ctx, str): try: