Opened 10 years ago
Closed 10 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 |
Description
Module: db.models.fields.files.py
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)
https://docs.djangoproject.com/en/1.7/howto/custom-file-storage/
"_save(name, content)¶ Called by Storage.save(). 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)
Change History (8)
by , 10 years ago
Attachment: | files.patch added |
---|
comment:1 by , 10 years ago
Component: | Database layer (models, ORM) → File uploads/storage |
---|---|
Needs documentation: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 10 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 , 10 years ago
Version: | 1.7 → master |
---|
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.
https://docs.djangoproject.com/en/1.7/howto/custom-file-storage/
get_valid_name(name)¶ 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 , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 10 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
I have created a pull request at https://github.com/django/django/pull/4603 with documentation & test cases based on the original patch.
comment:6 by , 10 years ago
Cc: | added |
---|
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.