Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/new_contributor_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/fields/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/file_storage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"
Expand Down Expand Up @@ -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")
9 changes: 9 additions & 0 deletions tests/file_storage/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Loading