mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-17 22:57:13 +00:00
remove file on failed download
This commit is contained in:
parent
5358eaa251
commit
d67d679baf
2 changed files with 5 additions and 9 deletions
|
|
@ -256,7 +256,8 @@ class S3FilesImpl(Files):
|
||||||
content = response["Body"].read()
|
content = response["Body"].read()
|
||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
if e.response["Error"]["Code"] == "NoSuchKey":
|
if e.response["Error"]["Code"] == "NoSuchKey":
|
||||||
raise ResourceNotFoundError(row["id"], "File content", "files.list()") from e
|
await self.sql_store.delete("openai_files", where={"id": file_id})
|
||||||
|
raise ResourceNotFoundError(file_id, "File", "files.list()") from e
|
||||||
raise RuntimeError(f"Failed to download file from S3: {e}") from e
|
raise RuntimeError(f"Failed to download file from S3: {e}") from e
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
|
|
|
||||||
|
|
@ -223,18 +223,13 @@ class TestS3FilesImpl:
|
||||||
# Directly delete the S3 object from the backend
|
# Directly delete the S3 object from the backend
|
||||||
s3_client.delete_object(Bucket=s3_config.bucket_name, Key=uploaded.id)
|
s3_client.delete_object(Bucket=s3_config.bucket_name, Key=uploaded.id)
|
||||||
|
|
||||||
retrieved_metadata_after = await s3_provider.openai_retrieve_file(uploaded.id) # TODO: this should fail
|
|
||||||
assert retrieved_metadata_after.id == uploaded.id
|
|
||||||
|
|
||||||
listed_files = await s3_provider.openai_list_files()
|
|
||||||
assert uploaded.id in [file.id for file in listed_files.data]
|
|
||||||
|
|
||||||
with pytest.raises(ResourceNotFoundError, match="not found") as exc_info:
|
with pytest.raises(ResourceNotFoundError, match="not found") as exc_info:
|
||||||
await s3_provider.openai_retrieve_file_content(uploaded.id)
|
await s3_provider.openai_retrieve_file_content(uploaded.id)
|
||||||
|
|
||||||
assert "content" in str(exc_info).lower()
|
|
||||||
assert uploaded.id in str(exc_info).lower()
|
assert uploaded.id in str(exc_info).lower()
|
||||||
|
|
||||||
|
listed_files = await s3_provider.openai_list_files()
|
||||||
|
assert uploaded.id not in [file.id for file in listed_files.data]
|
||||||
|
|
||||||
async def test_upload_file_s3_put_object_failure(self, s3_provider, sample_text_file, s3_config, s3_client):
|
async def test_upload_file_s3_put_object_failure(self, s3_provider, sample_text_file, s3_config, s3_client):
|
||||||
"""Test that put_object failure results in exception and no orphaned metadata."""
|
"""Test that put_object failure results in exception and no orphaned metadata."""
|
||||||
sample_text_file.filename = "test_s3_put_object_failure"
|
sample_text_file.filename = "test_s3_put_object_failure"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue