Skip to content

Commit a457235

Browse files
committed
Refactor to optionally load DatabasePushNotificationConfigStore
1 parent f62124a commit a457235

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/a2a/server/tasks/__init__.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
from a2a.server.tasks.base_push_notification_sender import (
66
BasePushNotificationSender,
77
)
8-
from a2a.server.tasks.database_push_notification_config_store import (
9-
DatabasePushNotificationConfigStore,
10-
)
118
from a2a.server.tasks.inmemory_push_notification_config_store import (
129
InMemoryPushNotificationConfigStore,
1310
)
@@ -46,6 +43,28 @@ def __init__(self, *args, **kwargs):
4643
) from _original_error
4744

4845

46+
try:
47+
from a2a.server.tasks.database_push_notification_config_store import (
48+
DatabasePushNotificationConfigStore, # type: ignore
49+
)
50+
except ImportError as e:
51+
_original_error = e
52+
# If the database push notification config store is not available, we can still use in-memory stores.
53+
logger.debug(
54+
'DatabasePushNotificationConfigStore not loaded. This is expected if database dependencies are not installed. Error: %s',
55+
e,
56+
)
57+
58+
class DatabasePushNotificationConfigStore: # type: ignore
59+
"""Placeholder for DatabasePushNotificationConfigStore when dependencies are not installed."""
60+
61+
def __init__(self, *args, **kwargs):
62+
raise ImportError(
63+
'To use DatabasePushNotificationConfigStore, its dependencies must be installed. '
64+
'You can install them with \'pip install "a2a-sdk[sql]"\''
65+
) from _original_error
66+
67+
4968
__all__ = [
5069
'BasePushNotificationSender',
5170
'DatabasePushNotificationConfigStore',

0 commit comments

Comments
 (0)