jazzband / sorl-thumbnail

Thumbnails for Django
https://sorl-thumbnail.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.74k stars 497 forks source link

Uncaught exception from django-minio-storage #637

Open jayvdb opened 4 years ago

jayvdb commented 4 years ago

The constructor of django-minio-storage with auto_create_bucket enabled raises an exception which maybe should be suppressed by THUMBNAIL_DEBUG = False

  File "/usr/lib/python3.8/site-packages/sorl/thumbnail/shortcuts.py", line 8, in get_thumbnail
    return default.backend.get_thumbnail(file_, geometry_string, **options)
  File "/usr/lib/python3.8/site-packages/sorl/thumbnail/base.py", line 74, in get_thumbnail
    source = ImageFile(file_)
  File "/usr/lib/python3.8/site-packages/sorl/thumbnail/images.py", line 112, in __init__
    if hasattr(self.storage, 'location'):
  File "/usr/lib/python3.8/site-packages/django/utils/functional.py", line 224, in inner
    self._setup()
  File "/usr/lib/python3.8/site-packages/sorl/thumbnail/default.py", line 24, in _setup
    self._wrapped = get_module_class(settings.THUMBNAIL_STORAGE)()
  File "/usr/lib/python3.8/site-packages/minio_storage/storage.py", line 360, in __init__
    super().__init__(
  File "/usr/lib/python3.8/site-packages/minio_storage/storage.py", line 75, in __init__
    self._init_check()
  File "/usr/lib/python3.8/site-packages/minio_storage/storage.py", line 81, in _init_check
    if self.auto_create_bucket and not self.client.bucket_exists(
  File "/usr/lib/python3.8/site-packages/minio/api.py", line 453, in bucket_exists
    self._url_open('HEAD', bucket_name=bucket_name)
  File "/usr/lib/python3.8/site-packages/minio/api.py", line 2035, in _url_open
    region = self._get_bucket_region(bucket_name)
  File "/usr/lib/python3.8/site-packages/minio/api.py", line 1965, in _get_bucket_region
    region = self._get_bucket_location(bucket_name)
  File "/usr/lib/python3.8/site-packages/minio/api.py", line 1998, in _get_bucket_location
    response = self._http.urlopen(method, url,
  File "/usr/lib/python3.8/site-packages/urllib3/poolmanager.py", line 330, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 747, in urlopen
    return self.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 747, in urlopen
    return self.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 747, in urlopen
    return self.urlopen(
  [Previous line repeated 2 more times]
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8081): Max retries exceeded with url: /media?location= (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f936a1dc790>: Failed to establish a new connection: [Errno 111] Connection refused'))
camilonova commented 3 years ago

@jayvdb can you update the status of this issue?

jayvdb commented 3 years ago

No change. This problem occurs much earlier than the code I fixed in my PR.

i.e. it occurs here: https://github.com/jazzband/sorl-thumbnail/pull/639/files#diff-d9ac5079d976ae60d043264e0e34a771af2b3a9593c4478e406d5b784af1aadbR74

camilonova commented 3 years ago

Please try to work on a PR to fix this issue. Should be great if we get this fixed

jayvdb commented 3 years ago

Perhaps you could comment on the implementation ideas at https://github.com/jazzband/sorl-thumbnail/issues/638#issuecomment-738574998 , which is the issue which impacts me more directly, more frequently, and thus likely to be an itch I have in the nearer term.

wrt this issue with django-minio-storage, is it worthwhile adding unit tests that exercise that specific storage, or just mock it?