Fix StorageManager.get_file_size_bytes() returns ClientError instead of None for invalid S3 links

This commit is contained in:
allegroai 2022-12-22 21:52:24 +02:00
parent d723299f1e
commit 3dee5854bd

View File

@ -619,6 +619,13 @@ class StorageHelper(object):
if isinstance(self._driver, _HttpDriver) and obj:
obj = self._driver._get_download_object(obj) # noqa
size = int(obj.headers.get("Content-Length", 0))
elif isinstance(self._driver, _Boto3Driver) and obj:
# noinspection PyBroadException
try:
# To catch botocore exceptions
size = obj.content_length # noqa
except Exception:
pass
elif hasattr(obj, "size"):
size = obj.size
# Google storage has the option to reload the object to get the size