[Django] #29454: Default size for django.core.files.uploadedfile is None and then len will raise error

5 views
Skip to first unread message

Django

unread,
May 28, 2018, 12:33:23 AM5/28/18
to django-...@googlegroups.com
#29454: Default size for django.core.files.uploadedfile is None and then len will
raise error
------------------------------------------------+------------------------
Reporter: jxltom | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: File uploads/storage | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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 as do not implement ```__len__``` method
if ```size``` is set as ```None```

--
Ticket URL: <https://code.djangoproject.com/ticket/29454>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 28, 2018, 7:56:17 AM5/28/18
to django-...@googlegroups.com
#29454: Default size for django.core.files.uploadedfile is None and then len will
raise error
-------------------------------------+-------------------------------------
Reporter: jxltom | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: File | Version: 2.0
uploads/storage |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> 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 as do not implement ```__len__``` method
> if ```size``` is set as ```None```

New description:

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`.

--

Comment (by Tim Graham):

Did you find this to be a problem in practice?

--
Ticket URL: <https://code.djangoproject.com/ticket/29454#comment:1>

Django

unread,
Jun 5, 2018, 5:55:08 AM6/5/18
to django-...@googlegroups.com
#29454: Default size for django.core.files.uploadedfile is None and then len will
raise error
-------------------------------------+-------------------------------------
Reporter: jxltom | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: File | Version: 2.0
uploads/storage |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Windson yang):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29454#comment:2>

Django

unread,
Jun 7, 2018, 7:40:49 PM6/7/18
to django-...@googlegroups.com
#29454: Default size for django.core.files.uploadedfile is None and then len will
raise error
-------------------------------------+-------------------------------------
Reporter: jxltom | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: File | Version: 2.0
uploads/storage |
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => needsinfo


Comment:

Closing, absent some use case for the fix.

--
Ticket URL: <https://code.djangoproject.com/ticket/29454#comment:3>

Reply all
Reply to author
Forward
0 new messages