fix: guard against None converter results in RemoteA2aAgent#5199
Open
enjoykumawat wants to merge 2 commits intogoogle:mainfrom
Open
fix: guard against None converter results in RemoteA2aAgent#5199enjoykumawat wants to merge 2 commits intogoogle:mainfrom
enjoykumawat wants to merge 2 commits intogoogle:mainfrom
Conversation
2d6d1ba to
abd66a3
Compare
Converter functions (convert_a2a_message_to_event, convert_a2a_task_to_event) return Optional[Event], but several handler paths in RemoteA2aAgent access attributes on the result without checking for None first. This causes AttributeError when a converter returns None (e.g., for empty messages or metadata-only events). Add `if not event: return None` guards at all four call sites in both the legacy and new-style response handlers. Github-Issue: google#5187
abd66a3 to
2d26d1d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5187
RemoteA2aAgent._handle_a2a_responseand_handle_a2a_response_v2crash withAttributeErrorwhen converter functions (convert_a2a_task_to_event,convert_a2a_message_to_event, or config-based converters) returnNone. The code immediately accesses.custom_metadataon the result without checking forNone.None-checks after every converter call in both handler methods. When a converter returnsNone, the handler now gracefully returnsNone(skip the event) instead of crashing.TestHandleNoneConverterResultswith three test cases covering theNonereturn path for message converters and task converters in both v1 and v2 handlers.Test plan
python -m pytest tests/unittests/agents/test_remote_a2a_agent.py -v-- all 98 tests pass_handle_a2a_responsereturnsNonewhenconvert_a2a_message_to_eventreturnsNone_handle_a2a_responsereturnsNonewhenconvert_a2a_task_to_eventreturnsNone_handle_a2a_response_v2returnsNonewhena2a_message_converterreturnsNone