Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#26896 closed Bug (fixed)

FileSystemStorage no longer accepts reverse_lazy as base_url

Reported by: tpazderka Owned by: nobody
Component: File uploads/storage Version: 1.8
Severity: Normal Keywords: storage, reverse_lazy
Cc: Claude Paroz Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

Changes introduced with commit [fb9d8f06] fixing #22717 causes FileSystemStorage to evaluate the content of base_url uppon initialization.
This causes issues if the base_url is defined as reverse_lazy as it is resolved and can cause ImportError.

I think that the laziness of the base_url should be preserved. Either the check for the trailing slash can me moved to path generation or the __init__ can be updated to expect reverse_lazy as base_url.

Attachments (1)

0001-Test-for-reverse_lazy.patch (1.5 KB) - added by tpazderka 5 years ago.
Patch for tests/file_storage/tests.py

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by Tim Graham

Description: modified (diff)

Could you provide a test for tests/file_storage/tests.py that demonstrates your use case?

Changed 5 years ago by tpazderka

Patch for tests/file_storage/tests.py

comment:2 Changed 5 years ago by tpazderka

Not exactly our usecase as our failure is on ImportError which seems hard to test, but I hope that this patch shows the issue we are having.

The basic idea is that reverse_lazy should remain lazy as long as possible. Resolving the base_url on init() defeats the purpose of using reverse_lazy there.

comment:3 Changed 5 years ago by Tim Graham

Cc: Claude Paroz added

Should we skip that check if base_url is lazy or do you see some alternative?

comment:4 Changed 5 years ago by Claude Paroz

We should explore making base_url a descriptor, that might help delaying the check.

comment:5 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:6 Changed 5 years ago by tpazderka

Has patch: set

I have created a pull request https://github.com/django/django/pull/6989 which omitts the check if the base_url is not of string_types.

comment:7 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In b820b61:

Fixed #26896 -- Allowed a lazy base_url for FileSystemStorage.

comment:8 Changed 5 years ago by Tim Graham <timograham@…>

In d61dbc2:

[1.10.x] Fixed #26896 -- Allowed a lazy base_url for FileSystemStorage.

Backport of b820b6108a7d3f11ec18774d16d657f4f63fe9fa from master

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