Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid AWS_DEFAULT_ACL warning when overridden as a class variable #591

Merged
merged 1 commit into from Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion storages/backends/s3boto3.py
Expand Up @@ -277,7 +277,7 @@ def __init__(self, acl=None, bucket=None, **settings):
self.config = Config(**kwargs)

# warn about upcoming change in default AWS_DEFAULT_ACL setting
if not hasattr(django_settings, 'AWS_DEFAULT_ACL'):
if not hasattr(django_settings, 'AWS_DEFAULT_ACL') and self.default_acl == 'public-read':
warnings.warn(
"The default behavior of S3Boto3Storage is insecure and will change "
"in django-storages 2.0. By default files and new buckets are saved "
Expand Down
22 changes: 22 additions & 0 deletions tests/test_s3boto3.py
Expand Up @@ -579,3 +579,25 @@ def test_deprecated_bucket(self):
"argument will be removed in version 2.0."
)
assert str(w[-1].message) == message

def test_deprecated_default_acl(self):
with warnings.catch_warnings(record=True) as w:
s3boto3.S3Boto3Storage()
assert len(w) == 1
message = (
"The default behavior of S3Boto3Storage is insecure and will change "
"in django-storages 2.0. By default files and new buckets are saved "
"with an ACL of 'public-read' (globally publicly readable). Version 2.0 will "
"default to using the bucket's ACL. To opt into the new behavior set "
"AWS_DEFAULT_ACL = None, otherwise to silence this warning explicitly "
"set AWS_DEFAULT_ACL."
)
assert str(w[-1].message) == message

def test_deprecated_default_acl_override_class_variable(self):
class MyStorage(s3boto3.S3Boto3Storage):
default_acl = "private"

with warnings.catch_warnings(record=True) as w:
MyStorage()
assert len(w) == 0