From 6bd7d905b8d347cdbcf59233d4996566b4dc377a Mon Sep 17 00:00:00 2001 From: Akshat Kumar Date: Wed, 25 Feb 2026 01:40:54 +0530 Subject: [PATCH 1/5] 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 --- src/google/adk/sessions/__init__.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/google/adk/sessions/__init__.py b/src/google/adk/sessions/__init__.py index 7505eda346..48999ef742 100644 --- a/src/google/adk/sessions/__init__.py +++ b/src/google/adk/sessions/__init__.py @@ -17,6 +17,14 @@ from .state import State from .vertex_ai_session_service import VertexAiSessionService +try: + from .database_session_service import DatabaseSessionService +except ImportError: + # This handles the case where optional dependencies (like sqlalchemy) + # are not installed. Using a top-level import ensures documentation + # tools can "see" the class. + pass + __all__ = [ 'BaseSessionService', 'DatabaseSessionService', @@ -25,17 +33,3 @@ 'State', 'VertexAiSessionService', ] - - -def __getattr__(name: str): - if name == 'DatabaseSessionService': - try: - from .database_session_service import DatabaseSessionService - - return DatabaseSessionService - except ImportError as e: - raise ImportError( - 'DatabaseSessionService requires sqlalchemy>=2.0, please ensure it is' - ' installed correctly.' - ) from e - raise AttributeError(f'module {__name__!r} has no attribute {name!r}') From e8526bf2d3b55c722ac5db73ac38ad2554f5aa39 Mon Sep 17 00:00:00 2001 From: Akshat Kumar Date: Wed, 25 Feb 2026 01:54:34 +0530 Subject: [PATCH 2/5] fix: ensures the symbol is discoverable by documentation tools and provides a helpful error message if instantiated without sqlalchemy installed. Signed-off-by: Akshat Kumar --- src/google/adk/sessions/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/google/adk/sessions/__init__.py b/src/google/adk/sessions/__init__.py index 48999ef742..2dfced97a0 100644 --- a/src/google/adk/sessions/__init__.py +++ b/src/google/adk/sessions/__init__.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from .base_session_service import BaseSessionService from .in_memory_session_service import InMemorySessionService from .session import Session @@ -21,9 +22,17 @@ from .database_session_service import DatabaseSessionService except ImportError: # This handles the case where optional dependencies (like sqlalchemy) - # are not installed. Using a top-level import ensures documentation - # tools can "see" the class. - pass + # are not installed. A placeholder class ensures the symbol is always + # available for documentation tools, providing a clear error message + # at runtime if used without the necessary dependencies. + class DatabaseSessionService: + + def __init__(self, *args, **kwargs): + raise ImportError( + 'DatabaseSessionService requires sqlalchemy>=2.0, please ensure it is' + ' installed correctly.' + ) + __all__ = [ 'BaseSessionService', From c701daa729d0e774d65688005a04c220abde13a3 Mon Sep 17 00:00:00 2001 From: Akshat Kumar Date: Wed, 25 Feb 2026 02:06:08 +0530 Subject: [PATCH 3/5] fix: type consistency for static analysis while maintaining robust error handling for missing dependencies. Signed-off-by: Akshat Kumar --- src/google/adk/sessions/__init__.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/google/adk/sessions/__init__.py b/src/google/adk/sessions/__init__.py index 2dfced97a0..1fc57a200a 100644 --- a/src/google/adk/sessions/__init__.py +++ b/src/google/adk/sessions/__init__.py @@ -23,9 +23,9 @@ except ImportError: # This handles the case where optional dependencies (like sqlalchemy) # are not installed. A placeholder class ensures the symbol is always - # available for documentation tools, providing a clear error message - # at runtime if used without the necessary dependencies. - class DatabaseSessionService: + # available for documentation tools and static analysis. + class DatabaseSessionService(BaseSessionService): + """Placeholder for DatabaseSessionService when dependencies are not installed.""" def __init__(self, *args, **kwargs): raise ImportError( @@ -33,6 +33,21 @@ def __init__(self, *args, **kwargs): ' installed correctly.' ) + async def create_session(self, *args, **kwargs): + self.__init__(*args, **kwargs) + + async def get_session(self, *args, **kwargs): + self.__init__(*args, **kwargs) + + async def list_sessions(self, *args, **kwargs): + self.__init__(*args, **kwargs) + + async def delete_session(self, *args, **kwargs): + self.__init__(*args, **kwargs) + + async def append_event(self, *args, **kwargs): + self.__init__(*args, **kwargs) + __all__ = [ 'BaseSessionService', From 2b8017b311b28babee222188f5d6f9cf86ccb85e Mon Sep 17 00:00:00 2001 From: Akshat Kumar Date: Wed, 25 Feb 2026 02:12:10 +0530 Subject: [PATCH 4/5] fix: suggested changes by gemeni Signed-off-by: Akshat Kumar --- src/google/adk/sessions/__init__.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/google/adk/sessions/__init__.py b/src/google/adk/sessions/__init__.py index 1fc57a200a..bb621490e7 100644 --- a/src/google/adk/sessions/__init__.py +++ b/src/google/adk/sessions/__init__.py @@ -27,26 +27,28 @@ class DatabaseSessionService(BaseSessionService): """Placeholder for DatabaseSessionService when dependencies are not installed.""" + _ERROR_MESSAGE = ( + 'DatabaseSessionService requires sqlalchemy>=2.0, please ensure it is' + ' installed correctly.' + ) + def __init__(self, *args, **kwargs): - raise ImportError( - 'DatabaseSessionService requires sqlalchemy>=2.0, please ensure it is' - ' installed correctly.' - ) + raise ImportError(self._ERROR_MESSAGE) async def create_session(self, *args, **kwargs): - self.__init__(*args, **kwargs) + raise ImportError(self._ERROR_MESSAGE) async def get_session(self, *args, **kwargs): - self.__init__(*args, **kwargs) + raise ImportError(self._ERROR_MESSAGE) async def list_sessions(self, *args, **kwargs): - self.__init__(*args, **kwargs) + raise ImportError(self._ERROR_MESSAGE) async def delete_session(self, *args, **kwargs): - self.__init__(*args, **kwargs) + raise ImportError(self._ERROR_MESSAGE) async def append_event(self, *args, **kwargs): - self.__init__(*args, **kwargs) + raise ImportError(self._ERROR_MESSAGE) __all__ = [ From 323d97c010cb1a67c52fdde47165a20f5edbba93 Mon Sep 17 00:00:00 2001 From: Akshat Kumar Date: Wed, 25 Feb 2026 02:19:03 +0530 Subject: [PATCH 5/5] fix: style: add @override decorators to DatabaseSessionService placeholder per bot feedback Signed-off-by: Akshat Kumar --- src/google/adk/sessions/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/google/adk/sessions/__init__.py b/src/google/adk/sessions/__init__.py index bb621490e7..835b54e176 100644 --- a/src/google/adk/sessions/__init__.py +++ b/src/google/adk/sessions/__init__.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing_extensions import override + from .base_session_service import BaseSessionService from .in_memory_session_service import InMemorySessionService from .session import Session @@ -35,18 +37,23 @@ class DatabaseSessionService(BaseSessionService): def __init__(self, *args, **kwargs): raise ImportError(self._ERROR_MESSAGE) + @override async def create_session(self, *args, **kwargs): raise ImportError(self._ERROR_MESSAGE) + @override async def get_session(self, *args, **kwargs): raise ImportError(self._ERROR_MESSAGE) + @override async def list_sessions(self, *args, **kwargs): raise ImportError(self._ERROR_MESSAGE) + @override async def delete_session(self, *args, **kwargs): raise ImportError(self._ERROR_MESSAGE) + @override async def append_event(self, *args, **kwargs): raise ImportError(self._ERROR_MESSAGE)