-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[WIP]fix: validate transport types in ConfigClient and ConfigAsyncClient #15495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[WIP]fix: validate transport types in ConfigClient and ConfigAsyncClient #15495
Conversation
Co-authored-by: chalmerlowe <7291104+chalmerlowe@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello @chalmerlowe, 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 enhances the robustness of the Highlights
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly adds validation to prevent mismatches between client types (sync/async) and their transports. The changes are logical and the new tests provide good coverage. However, I've identified a critical bug in ConfigClient due to a missing import that will cause a NameError. I've also pointed out a few areas where the code can be simplified and duplication can be reduced to improve maintainability. Please see the detailed comments below.
| if ( | ||
| not _allow_async_transport | ||
| and transport_provided | ||
| and isinstance(transport, ConfigGrpcAsyncIOTransport) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| transport_provided = isinstance(transport, ConfigTransport) | ||
|
|
||
| if ( | ||
| transport_provided | ||
| and isinstance(transport, (ConfigGrpcTransport, ConfigRestTransport)) | ||
| ) or ( | ||
| isinstance(transport, str) and transport in ["grpc", "rest"] | ||
| ): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transport_provided variable is redundant here. The condition can be simplified by removing this variable and its usage, as isinstance(transport, (ConfigGrpcTransport, ConfigRestTransport)) already handles cases where transport is not a transport object (like a string).
if isinstance(transport, (ConfigGrpcTransport, ConfigRestTransport)) or (
isinstance(transport, str) and transport in ["grpc", "rest"]
):| if ( | ||
| not _allow_async_transport | ||
| and isinstance(transport, str) | ||
| and transport == "grpc_asyncio" | ||
| ): | ||
| raise ValueError( | ||
| "The `ConfigClient` does not support async transports. " | ||
| "Please use `ConfigAsyncClient` instead." | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Work-in-Progress.
This experimental PR is in response to a community request as found in Issue #13820. If we decide to incorporate such a change, we would need to identify the correct route to ensure that it can be autogenerated.
=====================================================
Prevents initialization of ConfigClient with async transports and ConfigAsyncClient with sync transports.
_allow_async_transportflag toConfigClient.__init__(default False).ConfigClient.__init__to raiseValueErrorif an async transport is provided and_allow_async_transportis False.ConfigAsyncClient.__init__to raiseValueErrorif a sync transport is provided.ConfigAsyncClientto initialize internalConfigClientwith_allow_async_transport=True.packages/google-cloud-config/tests/unit/gapic/config_v1/test_client_validation.py.packages/google-cloud-config/tests/unit/gapic/config_v1/test_config.pyto remove conflicting test cases.PR created automatically by Jules for task 2567066881583631619 started by @chalmerlowe