Opened 6 years ago

Closed 6 years ago

#29454 closed Cleanup/optimization (needsinfo)

Default size for django.core.files.uploadedfile is None and then len will raise error

Reported by: jxltom Owned by: nobody
Component: File uploads/storage Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

By default, size of django.core.files.uploadedfile is None and __len__ will return size by default. Calling len will raise TypeError: 'NoneType' object cannot be interpreted as an integer error if size is not assigned specifically.

Can this be handled better? Such not implementing __len__ method if size is set as None.

Change History (3)

comment:1 by Tim Graham, 6 years ago

Description: modified (diff)

Did you find this to be a problem in practice?

comment:2 by Windson yang, 6 years ago

the code is in https://github.com/django/django/blob/master/django/core/files/base.py#L28, I'm not sure we should handle if the file doesn't have size.

comment:3 by Tim Graham, 6 years ago

Resolution: needsinfo
Status: newclosed

Closing, absent some use case for the fix.

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