fix(google-genai): break circular reference in span event body#1883
Open
MukundaKatta wants to merge 1 commit intopydantic:mainfrom
Open
fix(google-genai): break circular reference in span event body#1883MukundaKatta wants to merge 1 commit intopydantic:mainfrom
MukundaKatta wants to merge 1 commit intopydantic:mainfrom
Conversation
Upstream `_to_dict` can return self-referential dicts (notably for uploaded Gemini File parts). `json.dumps` then raises `ValueError: Circular reference detected`, which `handle_internal_errors` swallows and the span event is lost. Fall back to a cycle-stripped copy that uses `safe_repr` for the back-edge so the event still gets emitted. Closes pydantic#1881.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #1881.
instrument_google_genaicallsjson.dumps(body, default=default_json)to attach the user/assistant payload to the span. When upstream_to_dictreturns a self-referential dict (for example for an uploaded GeminiFilepart) Python raisesValueError: Circular reference detected,handle_internal_errorslogs it as an internal error, and the span event is dropped silently.Catch that
ValueErrorand retry on a cycle-stripped copy: a small recursive walker swaps the back-edge withsafe_reprso the rest of the body still serializes cleanly. Test intests/otel_integrations/test_google_genai.py::test_span_event_logger_with_circular_reference.