fix(google-genai): prevent TypeError when handling Pydantic model class#3931
Open
arloc wants to merge 1 commit intoopen-telemetry:mainfrom
Open
fix(google-genai): prevent TypeError when handling Pydantic model class#3931arloc wants to merge 1 commit intoopen-telemetry:mainfrom
arloc wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
|
|
3f10d20 to
eeed5d7
Compare
eeed5d7 to
6045ec2
Compare
Member
|
@DylanRussell this covers some of the same things as #3905, but also includes the JSON schema. WDYT? |
Contributor
|
I just put |
Member
|
We have a semconv PR for tool schemas open-telemetry/semantic-conventions#2942. I think it's generally useful but maybe best to hold off until we have conventions. @arloc was capturing the schema in particular important to you or mostly just avoiding this exception? |
Member
|
We merged #2942, but I'll leave this open until we decide on including the json schema inline. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug in the
opentelemetry-instrumentation-google-genaipackage where passing an uninstantiated Pydantic model class (instead of an instance) to dict conversion functions would cause aTypeError:The issue occurred in three functions that attempt to convert objects to dictionaries:
_to_dict()ingenerate_content.py_to_otel_value()intool_call_wrapper.py_flatten_dict()indict_util.pyThese functions check
hasattr(value, "model_dump")which returnsTruefor both Pydantic classes and instances, butmodel_dump()is an instance method that cannot be called on the class itself.Solution:
isinstance(value, type)check to distinguish between classes and instances before callingmodel_dump()model_json_schema()(a classmethod) to get the schema representationFixes #3596
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Added unit tests to verify the fix:
test_flatten_with_pydantic_class_not_instance in
tests/utils/test_dict_util.pymodel_dump()errormodel_json_schema()test_handles_pydantic_class_not_instance in
tests/utils/test_tool_call_wrapper.pyDoes This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.