Skip to content

Commit 9cac4ac

Browse files
committed
suppress minio.error.S3Error exception floods during collectstatic execution
1 parent 097d085 commit 9cac4ac

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

django_minio_backend/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import mimetypes
1313
import ssl
1414
import datetime
15+
import sys
1516
from pathlib import Path
1617
from typing import Union, List, Tuple, Optional
1718
from concurrent.futures import ThreadPoolExecutor, as_completed
18-
from typing import Union, List
1919
import hashlib
2020
from datetime import timedelta
2121

@@ -34,7 +34,7 @@
3434
from django.core.cache import cache
3535

3636

37-
from .utils import MinioServerStatus, PrivatePublicMixedError, ConfigurationError, get_setting, get_storages_setting
37+
from .utils import MinioServerStatus, PrivatePublicMixedError, ConfigurationError, get_setting
3838

3939

4040
__all__ = ['MinioBackend', 'MinioBackendStatic', 'get_iso_date', 'iso_date_prefix', ]
@@ -305,7 +305,12 @@ def exists(self, name: str) -> bool:
305305
object_name = Path(name).as_posix()
306306
try:
307307
self.stat(object_name)
308-
except (minio.error.S3Error, minio.error.ServerError, urllib3.exceptions.MaxRetryError, AttributeError, FileNotFoundError) as e:
308+
except minio.error.S3Error as e:
309+
if ("collectstatic" in sys.argv) and getattr(e, "code", None) in {"NoSuchKey", "NoSuchObject"}:
310+
return False
311+
logger.info(msg=f"Object could not be found: {self.bucket}/{name}", exc_info=e)
312+
return False
313+
except (minio.error.ServerError, urllib3.exceptions.MaxRetryError, AttributeError, FileNotFoundError) as e:
309314
logger.info(msg=f"Object could not be found: {self.bucket}/{name}", exc_info=e)
310315
return False
311316
return True

0 commit comments

Comments
 (0)