fix: restore .text attribute when loading text artifacts from GCS#5155
fix: restore .text attribute when loading text artifacts from GCS#5155Maanik23 wants to merge 1 commit intogoogle:mainfrom
Conversation
GcsArtifactService._load_artifact() always used Part.from_bytes() which populates inline_data even for text/plain content. This caused Part.from_text() artifacts to lose their .text attribute after a save/load cycle. Now detects text/plain content type and returns Part(text=...) instead, matching the behavior of FileArtifactService which already handles this correctly. Fixes google#3157
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @Maanik23, thank you for creating this PR! It looks like you haven't signed the Contributor License Agreement (CLA) yet. Please sign the CLA so we can proceed with reviewing your contribution. You can find more information in the "checks" section at the bottom of the pull request. Thanks! |
|
I have signed the Google CLA at cla.developers.google.com. Could you please recheck? |
Fixes #3157
Summary
When artifacts are saved via
Part.from_text()usingGcsArtifactService, the.textattribute isNoneafter loading — the content is present in.inline_datainstead. This PR fixes the deserialization to correctly restore text artifacts.Root Cause
GcsArtifactService._save_artifact()stores text parts withcontent_type="text/plain", but_load_artifact()always usedPart.from_bytes()which populatesinline_dataregardless of content type.Before (broken):
After (fixed):
Why
startswithinstead of==Using
startswith("text/plain")handles potential charset suffixes liketext/plain; charset=utf-8that cloud storage providers may append.Consistency
FileArtifactServicealready handles this correctly (line 473:return types.Part(text=text)). This fix bringsGcsArtifactServicein line with that behavior.Test plan
test_text_artifact_roundtrip— parametrized across all three service types (InMemory, GCS, File)loaded.text == original_textafter save/load cycle.textand.inline_dataon failure