diff options
| author | Mike Edmunds <medmunds@gmail.com> | 2026-05-02 13:40:18 -0700 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2026-05-06 22:39:16 -0300 |
| commit | f25ad7c086eb694372a8ef08cb713556bcb366a2 (patch) | |
| tree | e56aba1c8b662ac6291e85c3ea3d133500c40211 | |
| parent | b1a9fe4360ad527f4c7bed90c7bf80278826e58d (diff) | |
Refs #35514 -- Added error for missing EMAIL_FILE_PATH setting.
Replaced TypeError in `os.path.abspath(None)` with ImproperlyConfigured
error when settings.EMAIL_FILE_PATH is required but missing.
| -rw-r--r-- | django/core/mail/backends/filebased.py | 4 | ||||
| -rw-r--r-- | tests/mail/test_backends.py | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/django/core/mail/backends/filebased.py b/django/core/mail/backends/filebased.py index 3b2b037150..07ca959a59 100644 --- a/django/core/mail/backends/filebased.py +++ b/django/core/mail/backends/filebased.py @@ -15,6 +15,10 @@ class EmailBackend(ConsoleEmailBackend): self.file_path = file_path else: self.file_path = getattr(settings, "EMAIL_FILE_PATH", None) + if self.file_path is None: + raise ImproperlyConfigured( + "The EMAIL_FILE_PATH setting must be set to use the file EmailBackend." + ) self.file_path = os.path.abspath(self.file_path) try: os.makedirs(self.file_path, exist_ok=True) diff --git a/tests/mail/test_backends.py b/tests/mail/test_backends.py index c0bab41b57..ba1f652b6d 100644 --- a/tests/mail/test_backends.py +++ b/tests/mail/test_backends.py @@ -253,6 +253,14 @@ class FileBackendTests(SharedEmailBackendTests, SimpleTestCase): backend = filebased.EmailBackend(file_path=file_path_override) self.assertEqual(backend.file_path, str(file_path_override)) + def test_error_if_email_file_path_setting_not_defined(self): + msg = "The EMAIL_FILE_PATH setting must be set to use the file EmailBackend." + with ( + self.settings(EMAIL_FILE_PATH=None), + self.assertRaisesMessage(ImproperlyConfigured, msg), + ): + filebased.EmailBackend() + def test_error_if_file_path_is_not_directory(self): tmp_file = Path(self.tmp_dir) / "ordinary-file" tmp_file.touch() |
