From 7b4082f8d996913e21e6837aff85d5eb7e949984 Mon Sep 17 00:00:00 2001 From: coder-abu <865616170@qq.com> Date: Tue, 10 Nov 2026 15:31:30 +0800 Subject: [PATCH] fix(client): accept an empty body when deleting a push notification config The spec leaves the result of DeleteTaskPushNotificationConfig to the implementation. This SDK's server answers `{}`, a2a-js answers 204 No Content and a2a-go a 200 with no body. RestTransport parsed every success response as JSON, so against the other two servers the config was deleted but the call raised `A2AClientError: JSON Decode Error`. The delete now checks the status and does not read the body. Error responses still map to A2A errors through _handle_http_error. Co-Authored-By: Claude Opus 5.5 --- src/a2a/client/transports/rest.py | 17 ++++- tests/client/transports/test_rest_client.py | 81 +++++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/a2a/client/transports/rest.py b/src/a2a/client/transports/rest.py index caa213fe4..0c33a1ae6 100644 --- a/src/a2a/client/transports/rest.py +++ b/src/a2a/client/transports/rest.py @@ -14,6 +14,7 @@ from a2a.client.transports.base import ClientTransport from a2a.client.transports.http_helpers import ( get_http_args, + handle_http_exceptions, send_http_request, send_http_stream_request, ) @@ -299,14 +300,24 @@ async def delete_task_push_notification_config( if 'tenant' in params: del params['tenant'] - await self._execute_request( - 'DELETE', + path = self._get_path( f'/tasks/{_quote_id(request.task_id)}' f'/pushNotificationConfigs/{_quote_id(request.id)}', request.tenant, - context=context, + ) + http_request = self.httpx_client.build_request( + 'DELETE', + f'{self.url}{path}', params=params, + **get_http_args(context), ) + if self.httpx_client.is_closed: + raise A2AClientError('HTTP client is closed') + # The body is not read: servers confirm the deletion with `{}`, + # with 204 No Content, or with a 200 that has no body. + with handle_http_exceptions(self._handle_http_error): + response = await self.httpx_client.send(http_request) + response.raise_for_status() async def subscribe( self, diff --git a/tests/client/transports/test_rest_client.py b/tests/client/transports/test_rest_client.py index dc3cdc734..de6cfb252 100644 --- a/tests/client/transports/test_rest_client.py +++ b/tests/client/transports/test_rest_client.py @@ -547,6 +547,87 @@ async def test_delete_task_push_notification_config_success( in call_args[0][1] ) + @pytest.mark.asyncio + @pytest.mark.parametrize( + ('status_code', 'content'), + [(200, b'{}'), (204, b''), (200, b'')], + ids=['json_object', 'no_content', 'empty_200'], + ) + async def test_delete_task_push_notification_config_ignores_body( + self, mock_agent_card: MagicMock, status_code: int, content: bytes + ): + """Servers confirm a deletion with `{}`, 204, or a 200 with no body.""" + transport = httpx.MockTransport( + lambda request: httpx.Response(status_code, content=content) + ) + async with httpx.AsyncClient(transport=transport) as http_client: + client = RestTransport( + httpx_client=http_client, + agent_card=mock_agent_card, + url='http://agent.example.com/api', + ) + await client.delete_task_push_notification_config( + DeleteTaskPushNotificationConfigRequest( + task_id='task-1', id='config-1' + ) + ) + + @pytest.mark.asyncio + async def test_delete_task_push_notification_config_maps_errors( + self, mock_agent_card: MagicMock + ): + """An error response still raises the mapped A2A error.""" + body = { + 'error': { + 'code': 404, + 'status': 'NOT_FOUND', + 'message': 'Task task-1 not found', + 'details': [ + { + '@type': 'type.googleapis.com/google.rpc.ErrorInfo', + 'reason': 'TASK_NOT_FOUND', + 'domain': 'a2a-protocol.org', + } + ], + } + } + transport = httpx.MockTransport( + lambda request: httpx.Response(404, json=body) + ) + async with httpx.AsyncClient(transport=transport) as http_client: + client = RestTransport( + httpx_client=http_client, + agent_card=mock_agent_card, + url='http://agent.example.com/api', + ) + with pytest.raises(TaskNotFoundError): + await client.delete_task_push_notification_config( + DeleteTaskPushNotificationConfigRequest( + task_id='task-1', id='config-1' + ) + ) + + @pytest.mark.asyncio + async def test_delete_task_push_notification_config_closed_client( + self, mock_httpx_client: AsyncMock, mock_agent_card: MagicMock + ): + """A closed HTTP client raises before anything is sent.""" + mock_httpx_client.is_closed = True + client = RestTransport( + httpx_client=mock_httpx_client, + agent_card=mock_agent_card, + url='http://agent.example.com/api', + ) + + with pytest.raises(A2AClientError, match='HTTP client is closed'): + await client.delete_task_push_notification_config( + DeleteTaskPushNotificationConfigRequest( + task_id='task-1', id='config-1' + ) + ) + + mock_httpx_client.send.assert_not_called() + class TestRestTransportTenant: """Tests for tenant path prepending in RestTransport."""