From dcbcf19da18e8cb95ac6f5231e2ba955d922599d Mon Sep 17 00:00:00 2001 From: rabbitblood Date: Wed, 22 Apr 2026 16:24:55 -0700 Subject: [PATCH] fix(test): guard msg.metadata assignment for non-Message returns new_agent_text_message returns a real Message object in production but some test mocks return a plain string. Guard with hasattr + try/except so the tool_trace assignment doesn't crash test_non_stream_events_ignored. --- workspace/a2a_executor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/workspace/a2a_executor.py b/workspace/a2a_executor.py index d48a1151..39ca159e 100644 --- a/workspace/a2a_executor.py +++ b/workspace/a2a_executor.py @@ -411,8 +411,13 @@ class LangGraphA2AExecutor(AgentExecutor): # immediately as the response (a2a_client.py reads .parts[0].text). # Streaming: yielded as the last SSE event in the stream. msg = new_agent_text_message(final_text, task_id=task_id, context_id=context_id) - if tool_trace: - msg.metadata = {"tool_trace": tool_trace} + # Attach tool_trace via metadata when supported. Guarded with + # hasattr because some test mocks return a plain string here. + if tool_trace and hasattr(msg, "metadata"): + try: + msg.metadata = {"tool_trace": tool_trace} + except (AttributeError, TypeError): + pass await event_queue.enqueue_event(msg) _result = final_text