[Django] #34540: [feature request] Run FileField storage callable during runtime and not during buildtime

11 views
Skip to first unread message

Django

unread,
May 4, 2023, 12:12:34 PM5/4/23
to django-...@googlegroups.com
#34540: [feature request] Run FileField storage callable during runtime and not
during buildtime
------------------------------------------------+------------------------
Reporter: Vasanth | Owner: nobody
Type: New feature | Status: new
Component: File uploads/storage | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
If the storage callable can be invoked during runtime similar to the
"upload_to", it can allow us to choose the storage to use dynamically.
This is particularly helpful for SaaS services which prefer maintaining
independent storages per client/subdomain.

Something like, the following snippet where ''local_state.tenant'' is
threading local() which holds the name of the tenant for each request


{{{
def tenant_storage():
tenant = getattr(local_state, "tenant", "default")
return storages[tenant]
}}}

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

Django

unread,
May 4, 2023, 12:13:16 PM5/4/23
to django-...@googlegroups.com
#34540: [feature request] Run FileField storage callable during runtime and not
during buildtime
-------------------------------------+-------------------------------------

Reporter: Vasanth | Owner: nobody
Type: New feature | Status: new
Component: File | Version: 4.2
uploads/storage |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Vasanth:

Old description:

> If the storage callable can be invoked during runtime similar to the
> "upload_to", it can allow us to choose the storage to use dynamically.
> This is particularly helpful for SaaS services which prefer maintaining
> independent storages per client/subdomain.
>
> Something like, the following snippet where ''local_state.tenant'' is
> threading local() which holds the name of the tenant for each request
>

> {{{
> def tenant_storage():
> tenant = getattr(local_state, "tenant", "default")
> return storages[tenant]
> }}}

New description:

If the storage callable can be invoked during runtime similar to the
"upload_to", it can allow us to choose the storage to use dynamically.
This is particularly helpful for SaaS services which prefer maintaining
independent storages per client/subdomain.

Something like, the following snippet where ''local_state.tenant'' is
threading local() which holds the name of the tenant for each request


{{{
def tenant_storage(instance, filename):


tenant = getattr(local_state, "tenant", "default")
return storages[tenant]
}}}

--

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

Django

unread,
May 4, 2023, 1:49:21 PM5/4/23
to django-...@googlegroups.com
#34540: [feature request] Run FileField storage callable during runtime and not
during buildtime
--------------------------------------+------------------------------------

Reporter: Vasanth | Owner: nobody
Type: New feature | Status: new
Component: File uploads/storage | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* version: 4.2 => dev
* stage: Unreviewed => Accepted


Comment:

Accepting since I agree that there is no need to evaluate the callable at
field creation time, and that there is value in having consistency between
`upload_to` and `storage`.

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

Django

unread,
May 4, 2023, 1:50:47 PM5/4/23
to django-...@googlegroups.com
#34540: [feature request] Run FileField storage callable during runtime and not
during buildtime
--------------------------------------+------------------------------------
Reporter: Vasanth | Owner: nobody
Type: New feature | Status: new
Component: File uploads/storage | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Natalia Bidart):

Actually on a second thought, this may be best decided in the forum to
have a wider audience. Posting there!

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

Django

unread,
May 4, 2023, 2:17:51 PM5/4/23
to django-...@googlegroups.com
#34540: [feature request] Run FileField storage callable during runtime and not
during buildtime
--------------------------------------+------------------------------------
Reporter: Vasanth | Owner: nobody
Type: New feature | Status: new
Component: File uploads/storage | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Mariusz Felisiak):

Also, this is a
[https://docs.djangoproject.com/en/stable/topics/files/#using-a-callable
documented] behavior so we cannot change it without the deprecation path:
> ''"Your callable will be evaluated when your models classes are loaded,
and must return an instance of Storage."''

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

Django

unread,
May 4, 2023, 3:21:25 PM5/4/23
to django-...@googlegroups.com
#34540: [feature request] Run FileField storage callable during runtime and not
during buildtime
--------------------------------------+------------------------------------
Reporter: Vasanth | Owner: nobody
Type: New feature | Status: closed

Component: File uploads/storage | Version: dev
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Natalia Bidart):

* status: new => closed
* resolution: => wontfix


Comment:

Replying to [comment:4 Mariusz Felisiak]:


> Also, this is a
[https://docs.djangoproject.com/en/stable/topics/files/#using-a-callable
documented] behavior so we cannot change it without the deprecation path:
> > ''"Your callable will be evaluated when your models classes are
loaded, and must return an instance of Storage."''
>

> -1 from me.

Good point, I'll close for now as `wontfix`, then if there is enough
traction in the forum we can revisit. Thanks!

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

Reply all
Reply to author
Forward
0 new messages