fix(utils): Avoid double serialization of strings in safe_serialize#5587
Open
ericapisani wants to merge 3 commits intomasterfrom
Open
fix(utils): Avoid double serialization of strings in safe_serialize#5587ericapisani wants to merge 3 commits intomasterfrom
ericapisani wants to merge 3 commits intomasterfrom
Conversation
When serialize_item() already returns a string (for plain strings, callables, or objects with __dict__), skip json.dumps to prevent wrapping the value in extra quotes with escaped characters. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Documentation 📚
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 12.55s All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 13794 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
Contributor
Codecov Results 📊✅ 4 passed | Total: 4 | Pass Rate: 100% | Execution Time: 624ms 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 15445 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 22.41% 21.90% -0.51%
==========================================
Files 189 189 —
Lines 19902 19777 -125
Branches 6464 6456 -8
==========================================
+ Hits 4461 4332 -129
- Misses 15441 15445 +4
- Partials 374 374 —Generated by Codecov Action |
Remove wrapping double quotes from expected tool output strings in google_genai tests. The safe_serialize fix (5937e9c) now correctly returns plain strings without passing them through json.dumps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove extra quoting from string argument assertions and fix double-serialized tool result expectations. The safe_serialize fix in 5937e9c eliminated double serialization of strings, so test expectations need to match the new single-serialized output. Co-Authored-By: Claude <noreply@anthropic.com>
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.
When
serialize_item()insidesafe_serialize()already returns a string(for plain strings, callables, or objects with
__dict__), the subsequentjson.dumps()call wraps it in extra quotes with escaped characters. Forexample, a JSON string
'{"param": "value"}'becomes'"{\\"param\\": \\"value\\"}"'.This was causing double-serialized tool arguments in pydantic-ai
integrations.
The fix skips
json.dumpswhenserialize_itemhas already produced astring, and adds tests covering plain strings, JSON strings, dicts,
callables, and objects.
Part of PY-2114