Skip to content

Commit af9437f

Browse files
fix(compat): return result: null for v0.3 pushNotificationConfig/delete (#1481)
# Description With `enable_v0_3_compat=True`, a successful v0.3 `tasks/pushNotificationConfig/delete` was answered with `{"id": 1, "jsonrpc": "2.0"}`, with neither `result` nor `error`. JSON-RPC 2.0 §5 requires `result` on success, the v0.3 schema requires `result: null` here, and the SDK's own v0.3 response type rejects the body. The v1.0 JSON-RPC path already returns `"result": null`. **Cause:** `JSONRPC03Adapter._process_non_streaming_request` dumps the response with `exclude_none=True`, which also drops the `None` result of the delete success response. **Fix:** keep `exclude_none=True` (so unset optional fields stay out) and put `result` back with `content.setdefault('result', None)`. Only success responses go through this code path, so error responses are unaffected; for every other method `result` is already set. ## Testing New test in `tests/compat/v0_3/test_jsonrpc_app_compat.py`. Before the fix: ``` AssertionError: assert {'id': '5', 'jsonrpc': '2.0'} == {'id': '5', 'jsonrpc': '2.0', 'result': None} ``` After: ``` $ pytest tests/compat/v0_3 -k delete 1 passed ``` Full suite on main (c16cab1): ``` $ pytest tests --ignore=tests/integration/cross_version 2618 passed, 215 skipped, 4 xfailed, 1 xpassed ``` `ruff check`, `ruff format` and `ty check` pass on the changed files. - [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 - [x] Appropriate docs were updated (if necessary) Fixes #1480 🦕 Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>
1 parent a01d990 commit af9437f

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

‎src/a2a/compat/v0_3/jsonrpc_adapter.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,13 @@ async def _process_non_streaming_request(
240240
else:
241241
raise ValueError(f'Unsupported method {method}')
242242

243-
return JSONResponse(
244-
content=result.model_dump(
245-
mode='json', by_alias=True, exclude_none=True
246-
)
243+
content = result.model_dump(
244+
mode='json', by_alias=True, exclude_none=True
247245
)
246+
# exclude_none also drops the null result of a successful delete, but
247+
# JSON-RPC 2.0 requires the result member in every success response.
248+
content.setdefault('result', None)
249+
return JSONResponse(content=content)
248250

249251
@validate_version(constants.PROTOCOL_VERSION_0_3)
250252
async def _process_streaming_request(

‎tests/compat/v0_3/test_jsonrpc_app_compat.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from a2a.compat.v0_3 import jsonrpc_adapter
9+
from a2a.compat.v0_3 import jsonrpc_adapter, types as types_v03
1010
from a2a.compat.v0_3.jsonrpc_adapter import JSONRPC03Adapter
1111
from a2a.server.context import ServerCallContext
1212
from a2a.server.request_handlers.request_handler import RequestHandler
@@ -165,6 +165,26 @@ def test_get_task_v03_compat(
165165
assert data['result']['status']['state'] == 'completed'
166166

167167

168+
def test_delete_push_notification_config_v03_compat_returns_null_result(
169+
client: TestClient, mock_handler: AsyncMock
170+
) -> None:
171+
"""A successful delete carries `"result": null`, as JSON-RPC 2.0 requires."""
172+
mock_handler.on_delete_task_push_notification_config.return_value = None
173+
request_payload = {
174+
'jsonrpc': '2.0',
175+
'id': '5',
176+
'method': 'tasks/pushNotificationConfig/delete',
177+
'params': {'id': 'test_task_id', 'pushNotificationConfigId': 'cfg'},
178+
}
179+
180+
response = client.post('/', json=request_payload)
181+
assert response.status_code == 200
182+
data = response.json()
183+
184+
assert data == {'jsonrpc': '2.0', 'id': '5', 'result': None}
185+
types_v03.DeleteTaskPushNotificationConfigResponse.model_validate(data)
186+
187+
168188
def test_get_extended_agent_card_v03_compat(
169189
client: TestClient, mock_handler: AsyncMock, agent_card: AgentCard
170190
) -> None:

0 commit comments

Comments
 (0)