Opened 9 years ago
Last modified 9 years ago
#26495 closed Cleanup/optimization
Storage save method wraps StringIO in File object which is identified as False. — at Initial Version
Reported by: | Maxim Novikov | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
https://github.com/django/django/blob/master/django/core/files/storage.py#L50
class Storage(object): def save(self, name, content, max_length=None): ... if not hasattr(content, 'chunks'): content = File(content)
Underlying libraries may use following pattern of code:
def store(data, name): data = data or ''
But File object without a name resolved into False which can produce bugs.
Possibly better to pass a name to File object. To ensure bool(content) is True
if not hasattr(content, 'chunks'): content = File(content, name=name)
Note:
See TracTickets
for help on using tickets.