Skip to content

Commit 09c9347

Browse files
coder-abuclaudemykytanetipa
authored
fix(client): accept an empty body when deleting a push notification config (a2aproject#1445)
# Description `RestTransport.delete_task_push_notification_config` goes through `_execute_request`, which always calls `response.json()`. The spec leaves the result to the server ([3.1.10](https://a2a-protocol.org/latest/specification/#3110-delete-push-notification-config): "Confirmation of deletion (implementation-specific)"), and the SDKs answer differently: - this SDK's server answers 200 with `{}`; - a2a-js answers 204 No Content ([`rest_handler.ts`](https://github.com/a2aproject/a2a-js/blob/3d3ca8291e1f6b1f53293f61c12ba46c36670000/src/server/express/rest_handler.ts#L548-L559)); - a2a-go answers 200 with no body ([`handleDeleteTaskPushConfig`](https://github.com/a2aproject/a2a-go/blob/ea739de3859f0574175bc9876eda39b7120da8e3/a2asrv/rest.go#L536-L557)). Against a2a-js or a2a-go servers, the config is deleted, but the Python client then raises `A2AClientError: JSON Decode Error`. A caller that retries or reports the failure is acting on a delete that succeeded. The delete now sends its request, checks the status, and does not read the body. Error responses still go through `_handle_http_error`, so a 404 with `TASK_NOT_FOUND` still raises `TaskNotFoundError`. `send_http_request` and the JSON-RPC transport are unchanged. The repro at the end of this description answers the delete the way each server does. On main (2cc1dd5): ``` a2a-python 200 b'{}' -> ok a2a-js 204 b'' -> A2AClientError: JSON Decode Error: Expecting value: line 1 column 1 (char 0) a2a-go 200 b'' -> A2AClientError: JSON Decode Error: Expecting value: line 1 column 1 (char 0) ``` On this branch, all three print `ok`. ``` $ pytest tests/client/transports/test_rest_client.py # src change reverted FAILED ...::TestTaskCallback::test_delete_task_push_notification_config_ignores_body[no_content] FAILED ...::TestTaskCallback::test_delete_task_push_notification_config_ignores_body[empty_200] 2 failed, 44 passed $ pytest --ignore=tests/integration/cross_version # this branch, Python 3.10, locked deps 2560 passed, 207 skipped, 4 xfailed, 1 xpassed $ pytest --cov=src src/a2a/client/transports/rest.py 87% (the new lines are covered) TOTAL 94% ``` The new tests also cover a mapped error and a closed client on this path. I left the cross-version tests out because their servers don't start within the 3 s timeout on my machine; the same happens on main. `ruff check`, `ruff format` and `ty check` pass. `ty` prints only the three existing unused `type: ignore` warnings. a2aproject#1439 touches `send_http_request` and the transport type hints. This change stays inside `delete_task_push_notification_config` to keep out of its way, apart from one added import. a2aproject#1436 percent-encodes the ids in this method's path, so whichever of the two lands second has a one-line conflict there; I'll rebase this one if a2aproject#1436 goes first. - [x] Follow the [`CONTRIBUTING` Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md). - [x] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - [x] Ensure the tests and linter pass (Run `bash scripts/format.sh` from the repository root to format) - [x] Appropriate docs were updated (if necessary) No issue exists, since the new tests reproduce it. <details><summary>Repro script</summary> ```python import asyncio import httpx from a2a.client.transports.rest import RestTransport from a2a.types.a2a_pb2 import AgentCard, DeleteTaskPushNotificationConfigRequest # How each SDK's server confirms DELETE /tasks/{id}/pushNotificationConfigs/{configId}. SERVERS = {'a2a-python': (200, b'{}'), 'a2a-js': (204, b''), 'a2a-go': (200, b'')} async def main() -> None: for name, (status, body) in SERVERS.items(): transport = httpx.MockTransport(lambda r, s=status, b=body: httpx.Response(s, content=b)) async with httpx.AsyncClient(transport=transport) as http: client = RestTransport(http, AgentCard(), 'http://agent.example') try: await client.delete_task_push_notification_config( DeleteTaskPushNotificationConfigRequest(task_id='t1', id='cfg1') ) print(f'{name:10} {status} {body!r:5} -> ok') except Exception as e: print(f'{name:10} {status} {body!r:5} -> {type(e).__name__}: {e}') asyncio.run(main()) ``` </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: mykytanetipa <mykytanetipa@google.com>
1 parent 8c48ad3 commit 09c9347

2 files changed

Lines changed: 95 additions & 3 deletions

File tree

‎src/a2a/client/transports/rest.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from a2a.client.transports.base import ClientTransport
1515
from a2a.client.transports.http_helpers import (
1616
get_http_args,
17+
handle_http_exceptions,
1718
send_http_request,
1819
send_http_stream_request,
1920
)
@@ -299,14 +300,24 @@ async def delete_task_push_notification_config(
299300
if 'tenant' in params:
300301
del params['tenant']
301302

302-
await self._execute_request(
303-
'DELETE',
303+
path = self._get_path(
304304
f'/tasks/{_quote_id(request.task_id)}'
305305
f'/pushNotificationConfigs/{_quote_id(request.id)}',
306306
request.tenant,
307-
context=context,
307+
)
308+
http_request = self.httpx_client.build_request(
309+
'DELETE',
310+
f'{self.url}{path}',
308311
params=params,
312+
**get_http_args(context),
309313
)
314+
if self.httpx_client.is_closed:
315+
raise A2AClientError('HTTP client is closed')
316+
# The body is not read: servers confirm the deletion with `{}`,
317+
# with 204 No Content, or with a 200 that has no body.
318+
with handle_http_exceptions(self._handle_http_error):
319+
response = await self.httpx_client.send(http_request)
320+
response.raise_for_status()
310321

311322
async def subscribe(
312323
self,

‎tests/client/transports/test_rest_client.py‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,87 @@ async def test_delete_task_push_notification_config_success(
549549
in call_args[0][1]
550550
)
551551

552+
@pytest.mark.asyncio
553+
@pytest.mark.parametrize(
554+
('status_code', 'content'),
555+
[(200, b'{}'), (204, b''), (200, b'')],
556+
ids=['json_object', 'no_content', 'empty_200'],
557+
)
558+
async def test_delete_task_push_notification_config_ignores_body(
559+
self, mock_agent_card: MagicMock, status_code: int, content: bytes
560+
):
561+
"""Servers confirm a deletion with `{}`, 204, or a 200 with no body."""
562+
transport = httpx.MockTransport(
563+
lambda request: httpx.Response(status_code, content=content)
564+
)
565+
async with httpx.AsyncClient(transport=transport) as http_client:
566+
client = RestTransport(
567+
httpx_client=http_client,
568+
agent_card=mock_agent_card,
569+
url='http://agent.example.com/api',
570+
)
571+
await client.delete_task_push_notification_config(
572+
DeleteTaskPushNotificationConfigRequest(
573+
task_id='task-1', id='config-1'
574+
)
575+
)
576+
577+
@pytest.mark.asyncio
578+
async def test_delete_task_push_notification_config_maps_errors(
579+
self, mock_agent_card: MagicMock
580+
):
581+
"""An error response still raises the mapped A2A error."""
582+
body = {
583+
'error': {
584+
'code': 404,
585+
'status': 'NOT_FOUND',
586+
'message': 'Task task-1 not found',
587+
'details': [
588+
{
589+
'@type': 'type.googleapis.com/google.rpc.ErrorInfo',
590+
'reason': 'TASK_NOT_FOUND',
591+
'domain': 'a2a-protocol.org',
592+
}
593+
],
594+
}
595+
}
596+
transport = httpx.MockTransport(
597+
lambda request: httpx.Response(404, json=body)
598+
)
599+
async with httpx.AsyncClient(transport=transport) as http_client:
600+
client = RestTransport(
601+
httpx_client=http_client,
602+
agent_card=mock_agent_card,
603+
url='http://agent.example.com/api',
604+
)
605+
with pytest.raises(TaskNotFoundError):
606+
await client.delete_task_push_notification_config(
607+
DeleteTaskPushNotificationConfigRequest(
608+
task_id='task-1', id='config-1'
609+
)
610+
)
611+
612+
@pytest.mark.asyncio
613+
async def test_delete_task_push_notification_config_closed_client(
614+
self, mock_httpx_client: AsyncMock, mock_agent_card: MagicMock
615+
):
616+
"""A closed HTTP client raises before anything is sent."""
617+
mock_httpx_client.is_closed = True
618+
client = RestTransport(
619+
httpx_client=mock_httpx_client,
620+
agent_card=mock_agent_card,
621+
url='http://agent.example.com/api',
622+
)
623+
624+
with pytest.raises(A2AClientError, match='HTTP client is closed'):
625+
await client.delete_task_push_notification_config(
626+
DeleteTaskPushNotificationConfigRequest(
627+
task_id='task-1', id='config-1'
628+
)
629+
)
630+
631+
mock_httpx_client.send.assert_not_called()
632+
552633

553634
class TestRestTransportTenant:
554635
"""Tests for tenant path prepending in RestTransport."""

0 commit comments

Comments
 (0)