From 9eeb8c3dbc8874fe01532ccaa09700362805922c Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Fri, 29 Sep 2023 01:20:53 -0400 Subject: [PATCH] [s3] raise ImproperlyConfigured if no bucket name is set (#1313) --- storages/backends/s3.py | 2 ++ tests/test_s3.py | 5 +++++ 2 files changed, 7 insertions(+) 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):