Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
warn about AWS_PRELOAD_METADATA only if preload_metadata is not True …
Browse files Browse the repository at this point in the history
…on the static storage backend
  • Loading branch information
smcoll authored and antonagestam committed Dec 8, 2017
1 parent 66b570d commit 71189c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions collectfast/management/commands/collectstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ def __init__(self, *args, **kwargs):
self.num_copied_files = 0
self.tasks = []
self.etags = {}
self.storage.preload_metadata = True
self.collectfast_enabled = settings.enabled
if not settings.preload_metadata_enabled:
if self.storage.preload_metadata is not True:
self.storage.preload_metadata = True
warnings.warn(
"Collectfast does not work properly without "
"`AWS_PRELOAD_METADATA` set to `True`. Overriding "
"`preload_metadata` set to `True` on the storage class. Try"
"setting `AWS_PRELOAD_METADATA` to `True`. Overriding "
"`storage.preload_metadata` and continuing.")

def set_options(self, **options):
Expand Down
2 changes: 0 additions & 2 deletions collectfast/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@
cache = getattr(settings, "COLLECTFAST_CACHE", "default")
threads = getattr(settings, "COLLECTFAST_THREADS", False)
enabled = getattr(settings, "COLLECTFAST_ENABLED", True)
preload_metadata_enabled = True is getattr(
settings, 'AWS_PRELOAD_METADATA', False)
6 changes: 4 additions & 2 deletions collectfast/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.core.management import call_command
from django.utils.six import StringIO
from mock import patch

from .utils import test, clean_static_dir, create_static_file, override_setting
from .utils import with_bucket
Expand Down Expand Up @@ -40,9 +41,10 @@ def test_threads(case):


@test
@override_setting("preload_metadata_enabled", False)
@with_bucket
def test_warn_preload_metadata(case):
@patch('django.contrib.staticfiles.management.commands.collectstatic.staticfiles_storage') # noqa
def test_warn_preload_metadata(case, mocked):
mocked.staticfiles_storage.return_value = False
clean_static_dir()
create_static_file()
with warnings.catch_warnings(record=True) as w:
Expand Down

0 comments on commit 71189c7

Please sign in to comment.