attempt to harden ensure_bucket reliability
Docker server image / build-and-push (push) Successful in 3m20s

This commit is contained in:
2026-03-27 17:53:32 -07:00
parent 407a920208
commit 3e8e6bd543
@@ -39,9 +39,19 @@ class S3Store:
) )
def ensure_bucket(self, bucket_name: str) -> None: def ensure_bucket(self, bucket_name: str) -> None:
"""Create a bucket if it does not already exist.""" """Create a bucket if it does not already exist.
if not self._client.bucket_exists(bucket_name):
Uses CreateBucket only, not HeadBucket. Some S3-compatible stores
(including SeaweedFS) mishandle or over-restrict HeadBucket; the MinIO
client's bucket_exists() maps non-NoSuchBucket errors to failures.
Idempotent create covers the same contract with fewer round trips.
"""
try:
self._client.make_bucket(bucket_name) self._client.make_bucket(bucket_name)
except S3Error as exc:
if exc.code in ("BucketAlreadyOwnedByYou", "BucketAlreadyExists"):
return
raise
def presigned_put_url(self, bucket_name: str, object_key: str, *, ttl_seconds: int) -> str: def presigned_put_url(self, bucket_name: str, object_key: str, *, ttl_seconds: int) -> str:
"""Generate a presigned PUT URL for a single object upload.""" """Generate a presigned PUT URL for a single object upload."""