[Django] #28474: DurationField does not handle OverflowError if an out of range input is passed

11 views
Skip to first unread message

Django

unread,
Aug 7, 2017, 11:01:06 AM8/7/17
to django-...@googlegroups.com
#28474: DurationField does not handle OverflowError if an out of range input is
passed
-----------------------------------------+------------------------
Reporter: Vikas | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
If an input with large number of days (e.g. `1000000000 10:11:12`) is
passed to `forms.DurationField`, the view crashes with the following
exception message:

{{{
Exception Type: OverflowError at /path/name/
Exception Value: days=1000000000; must have magnitude <= 999999999
}}}

The full traceback is given below:

{{{
Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/admin/project/listing/7/change/

Django Version: 1.10.7
Python Version: 3.5.3
Installed Applications:
['django.contrib.sites',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'project.apps.projectAppConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/core/handlers/exception.py" in inner
42. response = get_response(request)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e,
request)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request,
*callback_args, **callback_kwargs)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/contrib/admin/options.py" in wrapper
544. return self.admin_site.admin_view(view)(*args,
**kwargs)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/contrib/admin/sites.py" in inner
211. return view(request, *args, **kwargs)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/contrib/admin/options.py" in change_view
1512. return self.changeform_view(request, object_id, form_url,
extra_context)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2,
**kwargs2)

File "/usr/lib/python3.5/contextlib.py" in inner
30. return func(*args, **kwds)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/contrib/admin/options.py" in changeform_view
1441. if form.is_valid():

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/forms/forms.py" in is_valid
169. return self.is_bound and not self.errors

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/forms/forms.py" in errors
161. self.full_clean()

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/forms/forms.py" in full_clean
370. self._clean_fields()

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/forms/forms.py" in _clean_fields
388. value = field.clean(value)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/forms/fields.py" in clean
158. value = self.to_python(value)

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/forms/fields.py" in to_python
498. value = parse_duration(force_text(value))

File "/home/vikas/.virtualenvs/projectname/lib/python3.5/site-
packages/django/utils/dateparse.py" in parse_duration
127. return datetime.timedelta(**kw)

Exception Type: OverflowError at /admin/project/listing/7/change/
Exception Value: days=1000000000; must have magnitude <= 999999999

}}}

If a more ''long'' value is passed as days, the execption message changes
to

{{{
Python int too large to convert to C long
}}}

The expected behaviour would be to raise a `ValidationError` with message
like `Duration is too long` etc.

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

Django

unread,
Aug 7, 2017, 11:02:32 AM8/7/17
to django-...@googlegroups.com
#28474: DurationField does not handle OverflowError if an out of range input is
passed
------------------------+--------------------------------------
Reporter: Vikas | Owner: Vikas
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:

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

* status: new => assigned
* cc: Vikas (added)
* type: Uncategorized => Bug
* owner: nobody => Vikas


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

Django

unread,
Aug 7, 2017, 11:21:02 AM8/7/17
to django-...@googlegroups.com
#28474: DurationField does not handle OverflowError if an out of range input is
passed
------------------------+------------------------------------
Reporter: v1k45 | Owner: v1k45
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* stage: Unreviewed => Accepted


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

Django

unread,
Aug 8, 2017, 12:48:31 PM8/8/17
to django-...@googlegroups.com
#28474: DurationField does not handle OverflowError if an out of range input is
passed
-------------------------------------+-------------------------------------
Reporter: v1k45 | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Srinivas Reddy Thatiparthy):

* owner: v1k45 => Srinivas Reddy Thatiparthy


Comment:

PR has been raised here - https://github.com/django/django/pull/8870

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

Django

unread,
Aug 8, 2017, 1:14:49 PM8/8/17
to django-...@googlegroups.com
#28474: DurationField does not handle OverflowError if an out of range input is
passed
-------------------------------------+-------------------------------------
Reporter: v1k45 | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by v1k45):

Replying to [comment:3 Srinivas Reddy Thatiparthy]:


> PR has been raised here - https://github.com/django/django/pull/8870

Hey Srinivas, I assigned it to myself for a reason, I wanted to make my
first contribution to django by it.
You should at least notify the current owner before assigning it to
yourself, the current owner might be already working on it.
That said, the bug was meant to be fixed, doesn't matter who fixes it, so
no hard feelings :)

--
Ticket URL: <https://code.djangoproject.com/ticket/28474#comment:4>

Django

unread,
Aug 8, 2017, 3:06:57 PM8/8/17
to django-...@googlegroups.com
#28474: DurationField does not handle OverflowError if an out of range input is
passed
-------------------------------------+-------------------------------------
Reporter: v1k45 | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

Please check "Has patch" when adding a pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/28474#comment:5>

Django

unread,
Oct 25, 2017, 6:27:43 PM10/25/17
to django-...@googlegroups.com
#28474: DurationField does not handle OverflowError if an out of range input is
passed
-------------------------------------+-------------------------------------
Reporter: v1k45 | Owner: Srinivas
| Reddy Thatiparthy
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"55b5393bd235aa6c55ea9a7da6f0e8b75b204084" 55b5393]:
{{{
#!CommitTicketReference repository=""
revision="55b5393bd235aa6c55ea9a7da6f0e8b75b204084"
Fixed #28474 -- Made DurationField raise ValidationError for inputs that
raised OverflowError.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28474#comment:6>

Reply all
Reply to author
Forward
0 new messages