Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#34530 closed Cleanup/optimization (fixed)

Remove docs suggestion to use lambda for models.FileField(storage=...)

Reported by: Ran Benita Owned by: nobody
Component: Documentation Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The file storage docs https://docs.djangoproject.com/en/4.2/topics/files/#using-a-callable currently suggest the following:

upload = models.FileField(storage=lambda: storages["custom_storage"])

The migrations serializer however doesn't handle lambdas. So I think this paragraph should just be removed (the previous paragraph is good enough, using a named function).

Side note: it might have been nice to allow FileField(storage="foo") which will lazily take storages["foo"] and thus avoid the callable annoyance? But that's unrelated to this ticket.

Change History (9)

comment:1 by David Sanders, 19 months ago

Triage Stage: UnreviewedAccepted

Hi bluetech!

Thanks for identifying this 👍 Interested in submitting a PR?

comment:2 by David Sanders, 19 months ago

So I think this paragraph should just be removed (the previous paragraph is good enough, using a named function).

Personally I think an example involving storages is worth keeping though 🤷‍♂️

Side note: it might have been nice to allow FileField(storage="foo") which will lazily take storagesfoo and thus avoid the callable annoyance? But that's unrelated to this ticket.

Seems like something worth raising on the forum.

comment:3 by David Sanders, 19 months ago

Easy pickings: set

comment:4 by Ran Benita, 19 months ago

Thanks David, agreed about keeping an example using storages. I sent a PR.

Seems like something worth raising on the forum.

If I have some time I'll try checking if it makes sense first :)

comment:5 by Ran Benita, 19 months ago

Has patch: set
Summary: Remove docs suggestion to use lambda for models.FileField(storages=...)Remove docs suggestion to use lambda for models.FileField(storage=...)

comment:6 by Natalia Bidart, 19 months ago

comment:7 by Natalia Bidart, 19 months ago

Triage Stage: AcceptedReady for checkin
Type: UncategorizedCleanup/optimization

comment:8 by GitHub <noreply@…>, 19 months ago

Resolution: fixed
Status: newclosed

In 506f93f0:

Fixed #34530 -- Improved docs when customizing storage for FileField.

comment:9 by Natalia <124304+nessita@…>, 19 months ago

In 4c68482c:

[4.2.x] Fixed #34530 -- Improved docs when customizing storage for FileField.

Backport of 506f93f0c37ed9c44069edeab8baa66da5f7e03a from main

Note: See TracTickets for help on using tickets.
Back to Top