diff --git a/.github/workflows/new_contributor_pr.yml b/.github/workflows/new_contributor_pr.yml index fd09c27f5fc2..958ebc64d435 100644 --- a/.github/workflows/new_contributor_pr.yml +++ b/.github/workflows/new_contributor_pr.yml @@ -15,12 +15,12 @@ jobs: # Pin to v1: https://github.com/actions/first-interaction/issues/369 - uses: actions/first-interaction@v1 with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - issue_message: | + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: | Hello! Thank you for your interest in Django 💪 Django issues are tracked in [Trac](https://code.djangoproject.com/) and not in this repo. - pr_message: | + pr-message: | Hello! Thank you for your contribution 💪 As it's your first contribution be sure to check out the [patch review checklist](https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/submitting-patches/#patch-review-checklist). diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index 5216ff565fe3..dbf227ae92be 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -248,7 +248,7 @@ def __init__( ): self._primary_key_set_explicitly = "primary_key" in kwargs - self.storage = storage or default_storage + self.storage = storage if storage is not None else default_storage if callable(self.storage): # Hold a reference to the callable for deconstruct(). self._storage_callable = self.storage diff --git a/tests/file_storage/models.py b/tests/file_storage/models.py index 12a54edda57b..d1761c85105b 100644 --- a/tests/file_storage/models.py +++ b/tests/file_storage/models.py @@ -11,6 +11,7 @@ from django.core.files.storage import FileSystemStorage, default_storage from django.db import models +from django.utils.functional import LazyObject class CustomValidNameStorage(FileSystemStorage): @@ -37,6 +38,11 @@ def __call__(self): return self +class LazyTempStorage(LazyObject): + def _setup(self): + self._wrapped = temp_storage + + class Storage(models.Model): def custom_upload_to(self, filename): return "foo" @@ -82,3 +88,4 @@ def pathlib_upload_to(self, filename): extended_length = models.FileField( storage=temp_storage, upload_to="tests", max_length=1024 ) + lazy_storage = models.FileField(storage=LazyTempStorage(), upload_to="tests") diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index a0234b2f9d99..92962bd9a062 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -29,6 +29,7 @@ from django.urls import NoReverseMatch, reverse_lazy from django.utils import timezone from django.utils._os import symlinks_supported +from django.utils.functional import empty from .models import ( Storage, @@ -1267,3 +1268,11 @@ def test_nonexistent_backend(self): ) with self.assertRaisesMessage(InvalidStorageError, msg): test_storages["invalid_backend"] + + +class StorageLazyObjectTests(SimpleTestCase): + def test_lazy_object_is_not_evaluated_before_manual_access(self): + obj = Storage() + self.assertIs(obj.lazy_storage.storage._wrapped, empty) + # assertEqual triggers resolution. + self.assertEqual(obj.lazy_storage.storage, temp_storage)