Opened 9 years ago

Closed 9 years ago

#24105 closed Cleanup/optimization (fixed)

When upload_to is callable, storage.get_valid_name() does not get called

Reported by: John Bowen Owned by: Abhaya Agarwal
Component: File uploads/storage Version: dev
Severity: Normal Keywords: upload_to, get_valid_name
Cc: Abhaya Agarwal Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



Present in recent commits of versions 1.8 and 1.7
Commit: c1493879d98328040b36ad93cd104c0b3b546772
Commit: bbcbacf0ad4fc9aa89d13c35f4b084185b284a49

Summary summed it up. But maybe the Storage class should be calling get_valid_name like the docs suggest. -see (_save)

"_save(name, content)¶
Called by The name will already have gone through get_valid_name() and get_available_name(), and the content will be a File object itself."

Attachments (1)

files.patch (1.1 KB ) - added by John Bowen 9 years ago.

Download all attachments as: .zip

Change History (8)

by John Bowen, 9 years ago

Attachment: files.patch added

comment:1 by Tim Graham, 9 years ago

Component: Database layer (models, ORM)File uploads/storage
Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

This might be a reasonable change, but we need to think if it might break backwards compatibility in any way. It will also need tests and docs.

comment:2 by Berker Peksag, 9 years ago

Patch needs improvement: set

The patch raises a SyntaxError at the following line:

+                       directory_name, filename = os.path.split(self.upload_to(instance, filename)

The else clause is not needed:

if callable(self.upload_to):
    # do stuff
return os.path.join(self.get_directory_name(), self.get_filename(filename))

Indentation should be 4 spaces.

comment:3 by Abhaya Agarwal, 9 years ago

Version: 1.7master

With this change, the documentation of get_valid_name should also be updated to clarify that the passed name might come from upload_to also.

Returns a filename suitable for use with the underlying storage system. The name argument passed to this method is the original filename sent to the server, after having any path information removed.

comment:4 by Abhaya Agarwal, 9 years ago

Owner: changed from nobody to Abhaya Agarwal
Status: newassigned

comment:5 by Abhaya Agarwal, 9 years ago

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

I have created a pull request at with documentation & test cases based on the original patch.

comment:6 by Abhaya Agarwal, 9 years ago

Cc: Abhaya Agarwal added

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

Resolution: fixed
Status: assignedclosed

In 9de9c240:

Fixed #24105 -- Called Storage.get_valid_name() when upload_to is callable

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