Skip to content

Commit a09d41d

Browse files
committed
remove warning import. Few improvements
1 parent 98aaa94 commit a09d41d

4 files changed

Lines changed: 37 additions & 55 deletions

File tree

src/a2a/server/tasks/base_push_notification_sender.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import logging
3-
import warnings
43

54
import httpx
65

@@ -40,20 +39,18 @@ def __init__(
4039
backward compatibility with 1.0 callers that constructed
4140
the sender with a (typically dummy) ServerCallContext.
4241
Pass None (the default) in new code. A non-None
43-
value triggers a DeprecationWarning and is otherwise
42+
value logs a deprecation warning and is otherwise
4443
ignored.
4544
"""
4645
if context is not None:
47-
warnings.warn(
46+
logger.warning(
4847
'BasePushNotificationSender no longer uses the context '
4948
'parameter; it is accepted only for backward compatibility '
5049
'with 1.0 and will be removed in a future major version. '
5150
'Push notifications now fan out across all owners via '
5251
'PushNotificationConfigStore.get_info_for_dispatch; the '
5352
'caller identity is not carried into dispatch. Drop the '
54-
'context argument from the constructor call.',
55-
DeprecationWarning,
56-
stacklevel=2,
53+
'context argument from the constructor call.'
5754
)
5855
self._client = httpx_client
5956
self._config_store = config_store

src/a2a/server/tasks/database_push_notification_config_store.py

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
try:
10-
from sqlalchemy import Table, and_, delete, select
10+
from sqlalchemy import ColumnElement, Table, and_, delete, select
1111
from sqlalchemy.ext.asyncio import (
1212
AsyncEngine,
1313
AsyncSession,
@@ -304,24 +304,14 @@ async def set_info(
304304
owner,
305305
)
306306

307-
async def get_info(
307+
async def _select_configs(
308308
self,
309-
task_id: str,
310-
context: ServerCallContext,
309+
*predicates: 'ColumnElement[bool]',
311310
) -> list[TaskPushNotificationConfig]:
312-
"""Retrieves all push notification configurations for a task, for the given owner.
313-
314-
Used by the user-callable read endpoints.
315-
"""
311+
"""Loads configs matching the given predicates and decodes them."""
316312
await self._ensure_initialized()
317-
owner = self.owner_resolver(context)
318313
async with self.async_session_maker() as session:
319-
stmt = select(self.config_model).where(
320-
and_(
321-
self.config_model.task_id == task_id,
322-
self.config_model.owner == owner,
323-
)
324-
)
314+
stmt = select(self.config_model).where(and_(*predicates))
325315
result = await session.execute(stmt)
326316
models = result.scalars().all()
327317

@@ -334,10 +324,25 @@ async def get_info(
334324
'Could not deserialize push notification config for task %s, config %s, owner %s',
335325
model.task_id,
336326
model.config_id,
337-
owner,
327+
model.owner,
338328
)
339329
return configs
340330

331+
async def get_info(
332+
self,
333+
task_id: str,
334+
context: ServerCallContext,
335+
) -> list[TaskPushNotificationConfig]:
336+
"""Retrieves all push notification configurations for a task, for the given owner.
337+
338+
Used by the user-callable read endpoints.
339+
"""
340+
owner = self.owner_resolver(context)
341+
return await self._select_configs(
342+
self.config_model.task_id == task_id,
343+
self.config_model.owner == owner,
344+
)
345+
341346
async def get_info_for_dispatch(
342347
self,
343348
task_id: str,
@@ -346,26 +351,9 @@ async def get_info_for_dispatch(
346351
347352
Used by the push-notification dispatch path.
348353
"""
349-
await self._ensure_initialized()
350-
async with self.async_session_maker() as session:
351-
stmt = select(self.config_model).where(
352-
self.config_model.task_id == task_id
353-
)
354-
result = await session.execute(stmt)
355-
models = result.scalars().all()
356-
357-
configs = []
358-
for model in models:
359-
try:
360-
configs.append(self._from_orm(model))
361-
except ValueError: # noqa: PERF203
362-
logger.exception(
363-
'Could not deserialize push notification config for task %s, config %s, owner %s',
364-
model.task_id,
365-
model.config_id,
366-
model.owner,
367-
)
368-
return configs
354+
return await self._select_configs(
355+
self.config_model.task_id == task_id,
356+
)
369357

370358
async def delete_info(
371359
self,

src/a2a/server/tasks/push_notification_config_store.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import warnings
32

43
from abc import ABC, abstractmethod
54

@@ -54,19 +53,18 @@ async def get_info_for_dispatch(
5453
but is INCORRECT for any deployment with multiple owners: the
5554
empty context resolves to the empty-string owner partition and
5655
returns no configs (silently dropping every notification). A
57-
DeprecationWarning is emitted on every call to flag the
58-
misconfiguration. Custom subclasses MUST override this method
59-
to deliver notifications correctly in multi-owner deployments.
56+
warning is logged on every call to flag the misconfiguration.
57+
Custom subclasses MUST override this method to deliver
58+
notifications correctly in multi-owner deployments.
6059
"""
61-
warnings.warn(
62-
f'{type(self).__name__} does not override '
60+
logger.warning(
61+
'%s does not override '
6362
'PushNotificationConfigStore.get_info_for_dispatch; falling back '
6463
'to a context-less get_info call which silently drops '
6564
'notifications in any deployment with multiple owners. Override '
6665
'get_info_for_dispatch to return all configs for task_id across '
6766
'every owner.',
68-
DeprecationWarning,
69-
stacklevel=2,
67+
type(self).__name__,
7068
)
7169
return await self.get_info(task_id, ServerCallContext())
7270

tests/server/tasks/test_inmemory_push_notifications.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,10 @@ async def test_cross_user_dispatch_alice_registers_bob_triggers(
543543
) -> None:
544544
"""Alice registers; Bob triggers; Alice's webhook receives the POST.
545545
546-
This is the §2 worked example. ``send_notification`` carries no
547-
identity, so there is no notion of "who triggered this event"
548-
at the store layer. ``get_info_for_dispatch`` returns Alice's
549-
config because Alice registered it. The fact that the event
550-
was caused by Bob is not visible to (and not relevant for) the
546+
The send_notification carries no identity, so there is no notion of
547+
"who triggered this event" at the store layer. get_info_for_dispatch
548+
returns Alice's config because Alice registered it. The fact that the
549+
event was caused by Bob is not visible to (and not relevant for) the
551550
dispatch path.
552551
"""
553552
alice_context = ServerCallContext(user=SampleUser(user_name='alice'))

0 commit comments

Comments
 (0)