[Django] #31941: FileField with a callable storage does not deconstruct properly

9 views
Skip to first unread message

Django

unread,
Aug 24, 2020, 3:21:46 PM8/24/20
to django-...@googlegroups.com
#31941: FileField with a callable storage does not deconstruct properly
------------------------------------------------+------------------------
Reporter: Brian Helba | Owner: nobody
Type: Uncategorized | Status: new
Component: File uploads/storage | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
A FileField with a callable `storage` parameter should not actually
evaluate the callable when it is being deconstructed.

The documentation for a FileField with a callable `storage` parameter,
states:

> You can use a callable as the `storage` parameter for
`django.db.models.FileField` or `django.db.models.ImageField`. This allows
you to modify the used storage at runtime, selecting different storages
for different environments, for example.

However, by evaluating the callable during deconstuction, the assumption
that the Storage may vary at runtime is broken. Instead, when the
FileField is deconstructed (which happens during `makemigrations`), the
actual evaluated Storage is inlined into the deconstucted FileField.

The correct behavior should be to return a reference to the original
callable during deconstruction. Note that a FileField with a callable
`upload_to` parameter already behaves this way: the deconstructed value is
simply a reference to the callable.

---

This bug was introduced in the initial implementation which allowed the
`storage` parameter to be callable:
https://github.com/django/django/pull/8477 , which fixed the ticket
https://code.djangoproject.com/ticket/28184

--
Ticket URL: <https://code.djangoproject.com/ticket/31941>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 24, 2020, 3:24:48 PM8/24/20
to django-...@googlegroups.com
#31941: FileField with a callable storage does not deconstruct properly
-------------------------------------+-------------------------------------
Reporter: Brian Helba | Owner: Brian
| Helba
Type: Uncategorized | Status: assigned
Component: File | Version: 3.1
uploads/storage |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Brian Helba):

* owner: nobody => Brian Helba
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31941#comment:1>

Django

unread,
Aug 24, 2020, 3:29:56 PM8/24/20
to django-...@googlegroups.com
#31941: FileField with a callable storage does not deconstruct properly
-------------------------------------+-------------------------------------
Reporter: Brian Helba | Owner: Brian
| Helba
Type: Uncategorized | Status: assigned
Component: File | Version: 3.1
uploads/storage |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Brian Helba):

Here is a PR fixing the issue: https://github.com/django/django/pull/13343

--
Ticket URL: <https://code.djangoproject.com/ticket/31941#comment:2>

Django

unread,
Sep 1, 2020, 6:21:14 AM9/1/20
to django-...@googlegroups.com
#31941: FileField with a callable storage does not deconstruct properly
-------------------------------------+-------------------------------------
Reporter: Brian Helba | Owner: Brian
| Helba
Type: Bug | Status: assigned

Component: File | Version: 3.1
uploads/storage |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* type: Uncategorized => Bug
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Hi Brian. Thanks for the report.

--
Ticket URL: <https://code.djangoproject.com/ticket/31941#comment:3>

Django

unread,
Sep 2, 2020, 4:21:34 AM9/2/20
to django-...@googlegroups.com
#31941: FileField with a callable storage does not deconstruct properly
-------------------------------------+-------------------------------------
Reporter: Brian Helba | Owner: Brian
| Helba
Type: Bug | Status: assigned
Component: File | Version: 3.1
uploads/storage |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31941#comment:4>

Django

unread,
Sep 2, 2020, 5:06:37 AM9/2/20
to django-...@googlegroups.com
#31941: FileField with a callable storage does not deconstruct properly
-------------------------------------+-------------------------------------
Reporter: Brian Helba | Owner: Brian
| Helba
Type: Bug | Status: closed

Component: File | Version: 3.1
uploads/storage |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"2d42e23b6d8fd76f93a96b2310b2c9dfd441d009" 2d42e23b]:
{{{
#!CommitTicketReference repository=""
revision="2d42e23b6d8fd76f93a96b2310b2c9dfd441d009"
Fixed #31941 -- Corrected FileField.deconstruct() with a callable storage.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31941#comment:5>

Django

unread,
Sep 2, 2020, 5:08:15 AM9/2/20
to django-...@googlegroups.com
#31941: FileField with a callable storage does not deconstruct properly
-------------------------------------+-------------------------------------
Reporter: Brian Helba | Owner: Brian
| Helba
Type: Bug | Status: closed
Component: File | Version: 3.1
uploads/storage |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"c69c6886def1fc81a6d96d1474b58a435a38c23b" c69c6886]:
{{{
#!CommitTicketReference repository=""
revision="c69c6886def1fc81a6d96d1474b58a435a38c23b"
[3.1.x] Fixed #31941 -- Corrected FileField.deconstruct() with a callable
storage.

Backport of 2d42e23b6d8fd76f93a96b2310b2c9dfd441d009 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31941#comment:6>

Reply all
Reply to author
Forward
0 new messages