diff --git a/storages/backends/s3.py b/storages/backends/s3.py index cf5dbe42..fdfc03d2 100644 --- a/storages/backends/s3.py +++ b/storages/backends/s3.py @@ -288,6 +288,8 @@ def __init__(self, **settings): super().__init__(**settings) check_location(self) + if not self.bucket_name: + raise ImproperlyConfigured("Setting a bucket name is required.") if (self.access_key or self.secret_key) and self.session_profile: raise ImproperlyConfigured( diff --git a/tests/test_s3.py b/tests/test_s3.py index 629ace61..d866d54b 100644 --- a/tests/test_s3.py +++ b/tests/test_s3.py @@ -956,6 +956,11 @@ def test_auth_config(self): access_key="foo", secret_key="boo", session_profile="moo" ) + def test_bucket_name_required(self): + with override_settings(AWS_STORAGE_BUCKET_NAME=None): + with self.assertRaises(ImproperlyConfigured): + s3.S3Storage() + class S3StaticStorageTests(TestCase): def setUp(self):