Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/google/adk/artifacts/gcs_artifact_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _save_artifact(
data=artifact.inline_data.data,
content_type=artifact.inline_data.mime_type,
)
elif artifact.text:
elif artifact.text is not None:
blob.upload_from_string(
data=artifact.text,
content_type="text/plain",
Expand Down Expand Up @@ -263,11 +263,11 @@ def _load_artifact(
blob_name = self._get_blob_name(
app_name, user_id, filename, version, session_id
)
blob = self.bucket.blob(blob_name)
blob = self.bucket.get_blob(blob_name)
if not blob:
return None

artifact_bytes = blob.download_as_bytes()
if not artifact_bytes:
return None
artifact = types.Part.from_bytes(
data=artifact_bytes, mime_type=blob.content_type
)
Expand Down
29 changes: 29 additions & 0 deletions tests/unittests/artifacts/test_artifact_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,35 @@ async def test_get_artifact_version_out_of_index(
)


@pytest.mark.asyncio
async def test_gcs_save_and_load_empty_text_artifact(
artifact_service_factory,
):
"""GcsArtifactService should treat empty text as stored content."""
artifact_service = artifact_service_factory(ArtifactServiceType.GCS)
artifact = types.Part.from_text(text="")

version = await artifact_service.save_artifact(
app_name="app0",
user_id="user0",
session_id="123",
filename="empty.txt",
artifact=artifact,
)

assert version == 0
loaded_artifact = await artifact_service.load_artifact(
app_name="app0",
user_id="user0",
session_id="123",
filename="empty.txt",
)

assert loaded_artifact == types.Part.from_bytes(
data=b"", mime_type="text/plain"
)


@pytest.mark.asyncio
async def test_file_metadata_camelcase(tmp_path, artifact_service_factory):
"""Ensures FileArtifactService writes camelCase metadata without newlines."""
Expand Down