fix: make DatabaseSessionService visible to API documentation (#4331)#4608
fix: make DatabaseSessionService visible to API documentation (#4331)#4608Akshat8510 wants to merge 6 commits intogoogle:mainfrom
Conversation
…#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>
Summary of ChangesHello @Akshat8510, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
@gemini-code-assist/gemini review |
There was a problem hiding this comment.
Code Review
This pull request aims to make DatabaseSessionService visible to API documentation generators by replacing the __getattr__ lazy loading with a top-level try...except ImportError block. While this change successfully addresses the documentation issue, it introduces a critical runtime bug. When the optional sqlalchemy dependency is not installed, DatabaseSessionService is not defined, but it remains in __all__. This leads to an AttributeError on import * and a non-descriptive ImportError on direct import. I've suggested a fix to define a placeholder class in the except block to resolve this, ensuring the symbol is always present while providing a clear error message if used without the required dependencies.
There was a problem hiding this comment.
Code Review
This pull request aims to make DatabaseSessionService visible to API documentation tools by changing how it's imported. While the approach of using a top-level try...except block is correct for making the class discoverable, the current implementation has a couple of issues. Firstly, it can cause an AttributeError when using from google.adk.sessions import * if optional dependencies aren't installed, because DatabaseSessionService is listed in __all__ but won't be defined. Secondly, it removes the helpful error message that was previously raised when a user tried to use DatabaseSessionService without the necessary dependencies. I've suggested a change to define a placeholder class in the except block. This placeholder will raise an informative ImportError upon instantiation, which resolves both issues while keeping the class visible for documentation.
…ovides a helpful error message if instantiated without sqlalchemy installed. Signed-off-by: Akshat Kumar <akshat230405@gmail.com>
|
@gemini-code-assist/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where DatabaseSessionService was not visible to API documentation generators by replacing the __getattr__ lazy loading with a try...except block. This is a good approach. I've added one suggestion to improve the placeholder class by making it inherit from BaseSessionService. This will improve type compatibility for consumers of the library, especially for static analysis and runtime type checks.
…ror handling for missing dependencies. Signed-off-by: Akshat Kumar <akshat230405@gmail.com>
|
@gemini-code-assist/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the visibility issue of DatabaseSessionService for documentation tools by replacing the __getattr__ lazy loading with a try...except ImportError block. This is a good approach. I've added one suggestion to improve the implementation of the placeholder class for better readability and maintainability.
Signed-off-by: Akshat Kumar <akshat230405@gmail.com>
|
@gemini-code-assist/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the issue of DatabaseSessionService not being visible to API documentation generators by replacing the dynamic __getattr__ loading with a try...except ImportError block. This is a robust solution that ensures the class is discoverable by static analysis tools while preserving the optional dependency behavior. I have one suggestion to improve code consistency by using the @override decorator in the new placeholder class.
…older per bot feedback Signed-off-by: Akshat Kumar <akshat230405@gmail.com>
|
@gemini-code-assist/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issue of DatabaseSessionService not being visible to API documentation and static analysis tools. By replacing the __getattr__ lazy-loading mechanism with a try...except ImportError block and a placeholder class, the DatabaseSessionService symbol is now explicitly present in the module's namespace. This approach maintains the optional dependency behavior while ensuring proper discoverability for documentation generation, which is a significant improvement for maintainability and developer experience.
|
/gemini summary |
Summary of ChangesThis pull request addresses a critical issue where the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
|
|
Hi @wuliang229, I’ve finalized #4331 and addressed all architectural feedback, replaced lazy-loading with a top-level try/except, added a proper placeholder inheriting from |
|
The gemini-code-assist bot marked it as a significant improvement with no further concerns. Thanks! |
|
That's great to hear, @Akshat8510! I'm glad the feedback was helpful in refining the pull request. The changes look solid and effectively address the initial documentation visibility issue while maintaining robust optional dependency handling. Well done! |
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
DatabaseSessionService#4331Problem:
The
DatabaseSessionServiceclass was missing from the generated ADK API Reference. This occurred because the class was being lazily loaded via the__getattr__method ingoogle.adk.sessions. Static analysis tools and documentation generators (like Sphinx/autodoc) typically cannot discover attributes that are not present in the module's namespace at import time.Solution:
Replaced the
__getattr__lazy-loading logic with a top-leveltry...except ImportErrorblock. This ensures that theDatabaseSessionServicesymbol is explicitly present in the module's namespace, making it visible to documentation tools. This approach preserves the intended behavior of supportingDatabaseSessionServiceas an optional dependency (requiring SQLAlchemy) without causing crashes for users who do not have it installed.Testing Plan
Unit Tests:
Manual End-to-End (E2E) Tests:
Verified that the class is now correctly exported and visible in the module namespace by running a manual import check in the development environment:
python -c "from google.adk.sessions import DatabaseSessionService; print('Logic is perfect')"Output:
Logic is perfectChecklist