Skip to content

Commit 6bd7d90

Browse files
committed
fix: make DatabaseSessionService visible to API documentation (#4331)
Replaces lazy loading via __getattr__ with a top-level try-except import. This allows documentation generators to discover the class while maintaining support for optional dependencies. Signed-off-by: Akshat Kumar <akshat230405@gmail.com>
1 parent ee8d956 commit 6bd7d90

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/google/adk/sessions/__init__.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
from .state import State
1818
from .vertex_ai_session_service import VertexAiSessionService
1919

20+
try:
21+
from .database_session_service import DatabaseSessionService
22+
except ImportError:
23+
# This handles the case where optional dependencies (like sqlalchemy)
24+
# are not installed. Using a top-level import ensures documentation
25+
# tools can "see" the class.
26+
pass
27+
2028
__all__ = [
2129
'BaseSessionService',
2230
'DatabaseSessionService',
@@ -25,17 +33,3 @@
2533
'State',
2634
'VertexAiSessionService',
2735
]
28-
29-
30-
def __getattr__(name: str):
31-
if name == 'DatabaseSessionService':
32-
try:
33-
from .database_session_service import DatabaseSessionService
34-
35-
return DatabaseSessionService
36-
except ImportError as e:
37-
raise ImportError(
38-
'DatabaseSessionService requires sqlalchemy>=2.0, please ensure it is'
39-
' installed correctly.'
40-
) from e
41-
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')

0 commit comments

Comments
 (0)