Opened 8 years ago

Closed 8 years ago

Last modified 8 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 8 years ago.
Patch for tests/file_storage/tests.py

Download all attachments as: .zip

Change History (9)

comment:1 by Tim Graham, 8 years ago

Description: modified (diff)

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

by tpazderka, 8 years ago

Patch for tests/file_storage/tests.py

comment:2 by tpazderka, 8 years ago

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 by Tim Graham, 8 years ago

Cc: Claude Paroz added

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

comment:4 by Claude Paroz, 8 years ago

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

comment:5 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

comment:6 by tpazderka, 8 years ago

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 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In b820b61:

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

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

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