Skip to content
Open
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: 7 additions & 1 deletion backend/python/app/sources/external/s3/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ async def generate_presigned_url(self,
Returns:
S3Response: Standardized response with success/data/error format
"""
# Prepare kwargs explicitly outside the exception block for minor speedup
kwargs = {'ClientMethod': ClientMethod}
if Params is not None:
kwargs['Params'] = Params
Expand All @@ -1191,8 +1192,13 @@ async def generate_presigned_url(self,
kwargs['HttpMethod'] = HttpMethod

try:
session = await self._get_aioboto3_session()
# Session acquisition does not require awaiting again after first run due to caching
session = self._session or await self._get_aioboto3_session()
# Create client ASAP without context switching
async with session.client('s3') as s3_client:
# The signature matches aioboto3's async call pattern
# Using asyncio.to_thread is not needed here since this is an I/O-bound operation
# await directly
response = await getattr(s3_client, 'generate_presigned_url')(**kwargs)
return self._handle_s3_response(response)
except ClientError as e:
Expand Down