How to use Bucket.creation_date
dorinclisu opened this issue · comments
Dorin commented
- Async AWS SDK for Python version: 8.2.1
- Python version: 3.9
- Operating System: Debian Buster amd64
Simple attribute access:
async with aioboto3.resource('s3') as s3:
bucket: Bucket = await s3.Bucket('bucketname')
print(bucket.creation_date)
RuntimeWarning: coroutine 'AIOBoto3ResourceFactory._create_autoload_property.<locals>.property_loader' was never awaited
Awaiting attribute access:
async with aioboto3.resource('s3') as s3:
bucket: Bucket = await s3.Bucket('bucketname')
print(await bucket.creation_date)
Traceback (most recent call last):
File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/relay/api/photos.py", line 245, in <module>
asyncio.run(main())
File "/usr/local/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/relay/api/photos.py", line 234, in main
logging.debug(await bucket.creation_date)
File "/usr/local/lib/python3.9/site-packages/aioboto3/resources/factory.py", line 116, in property_loader
await self.load()
File "/usr/local/lib/python3.9/site-packages/boto3/s3/inject.py", line 73, in bucket_load
for bucket_data in response['Buckets']:
TypeError: 'coroutine' object is not subscriptable
sys:1: RuntimeWarning: coroutine 'AioBaseClient._make_api_call' was never awaited
Terri Cain commented
Change to print(await bucket.creation_date)
This is because upon accessing those properties it would synchronously load in the data required, and there wasn't a simple way to achieve that with async. I thought about doing it when you create the bucket, but then again, not everyone wants said attributes.
Dorin commented
Look again at my code, I've tried just that and it doesn't work.
Terri Cain commented
ooooh, looks like https://github.com/boto/boto3/blob/develop/boto3/s3/inject.py#L57-L79 will need to be patched, will hopefully work on that this week
Terri Cain commented
Fixed in v8.3.0