-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: Handle 'Any' type in OpenAPI Schema for Pydantic 2.11+ compatibility #3110
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?
fix: Handle 'Any' type in OpenAPI Schema for Pydantic 2.11+ compatibility #3110
Conversation
…lity - Modified Schema model to use 'object' type instead of 'Any' - Added _sanitize_schema() method to convert 'Any' to valid types - Added _create_default_schema() method for consistent defaults - Integrated sanitization in parameter, request body, and return value processing - Ensures compatibility with Pydantic >=2.11 while maintaining backward compatibility The OpenApiSpecParser was creating Schema(type='Any'), which is invalid in Pydantic 2.11+ that only accepts: 'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'. This fix applies defense-in-depth by handling the conversion at multiple levels: 1. Default schema creation uses 'object' type 2. Schema sanitization method converts any 'Any' types 3. Applied to parameters, request bodies, and return values Fixes google#3108
Summary of ChangesHello @ishanrajsingh, 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 resolves a Pydantic validation error (specifically 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
Thank you for this detailed pull request. The fix to handle the Any
type for Pydantic 2.11+ compatibility is well-explained and the defense-in-depth approach is solid. I've identified a few areas for improvement to enhance robustness and prevent potential runtime errors. My comments are below.
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Outdated
Show resolved
Hide resolved
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Outdated
Show resolved
Hide resolved
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Outdated
Show resolved
Hide resolved
…n_parser.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…n_parser.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…n_parser.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
/gemini review |
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 is a well-structured and thoughtful fix for the Pydantic 2.11+ compatibility issue. The introduction of _sanitize_schema
and _create_default_schema
methods provides a robust, multi-layered solution. I have found one critical issue in the implementation that I've detailed below. Addressing it will ensure your fix works as intended.
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Show resolved
Hide resolved
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.
updated opertation_parser.py
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.
removed duplicate schema class
/gemini review |
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
Thank you for this contribution. The pull request is well-documented and the approach of adding a sanitization layer to handle the Pydantic 2.11+ incompatibility is solid. The introduction of _create_default_schema
and the application of sanitization at multiple points demonstrate a good defensive programming strategy.
I have one major suggestion regarding the implementation of _sanitize_schema
to make it more robust by handling nested schemas recursively. Please see the detailed comment.
Description
Fixes Pydantic validation error when initializing
ApplicationIntegrationToolset
with OAuth configuration in Google ADK.Problem
The
OpenApiSpecParser
createsSchema
objects withtype='Any'
(line 148 inoperation_parser.py
), which is invalid in Pydantic >=2.11.Error Message:
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Schema
type.literal['array','boolean','integer','null','number','object','string']
Input should be 'array', 'boolean', 'integer', 'null', 'number', 'object' or 'string'
[type=literal_error, input_value='Any', input_type=str]
text
Pydantic 2.11+ only accepts these literal types:
'array'
,'boolean'
,'integer'
,'null'
,'number'
,'object'
,'string'
Root Cause
In
operation_parser.py
, the_process_return_value()
method defaults to:return_schema = Schema(type='Any') # Line 148 - INVALID in Pydantic 2.11+
text
This conflicts with dependencies like
google-cloud-aiplatform
that require Pydantic >=2.11, making it impossible to use both libraries together.Solution
Applied defense-in-depth fix with three layers of protection:
1. Modified
_process_return_value()
methodSchema(type='Any')
to use_create_default_schema()
Schema(type='object')
as a valid default2. Added
_sanitize_schema()
static method'Any'
or'any'
types to'object'
3. Added
_create_default_schema()
static methodSchema(type='object')
compliant with Pydantic 2.11+4. Applied sanitization in multiple locations
_process_operation_parameters()
- sanitizes parameter schemas_process_request_body()
- sanitizes request body and nested property schemas_process_return_value()
- sanitizes return value schemasChanges Made
File Modified:
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Lines Changed:
_sanitize_schema()
method_create_default_schema()
methodSchema(type='Any')
withself._create_default_schema()
Testing
✅ Verified with reproduction code from issue #3108
No ValidationError raised during initialization
connector_tool = ApplicationIntegrationToolset(
project="test_project",
location="australia-southeast1",
connection="test-connection",
actions=["SharePoint_files/GET_file_content_by_path"],
auth_scheme=oauth_scheme,
auth_credential=auth_credential
)
text
✅ Results:
ValidationError
exceptions raisedCompatibility
Related Issues
Fixes #3108
Additional Context
google-cloud-aiplatform
and other libraries requiring Pydantic 2.11+Checklist
Screenshots/Logs
Before Fix:
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Schema
type.literal['array','boolean','integer','null','number','object','string']
Input should be 'array', 'boolean', 'integer', 'null', 'number', 'object' or 'string'
[type=literal_error, input_value='Any', input_type=str]
text
After Fix:
✓ SUCCESS: Initialization successful! Fix verified.
✓ No ValidationError raised.
✓ ApplicationIntegrationToolset created successfully.
text
Reviewers
@seanzhou1023 (assigned maintainer for issue #3108)
Note: This fix uses 'object' as the default type instead of 'Any' because: