Opened 7 years ago

Closed 7 years ago

#28474 closed Bug (fixed)

DurationField does not handle OverflowError if an out of range input is passed

Reported by: v1k45 Owned by: Srinivas Reddy Thatiparthy
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: v1k45 Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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.

Change History (6)

comment:1 by v1k45, 7 years ago

Cc: v1k45 added
Owner: changed from nobody to v1k45
Status: newassigned
Type: UncategorizedBug

comment:2 by Tim Graham, 7 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Srinivas Reddy Thatiparthy, 7 years ago

Owner: changed from v1k45 to Srinivas Reddy Thatiparthy

in reply to:  3 comment:4 by v1k45, 7 years ago

Replying to 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 :)

comment:5 by Tim Graham, 7 years ago

Has patch: set

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

comment:6 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 55b5393:

Fixed #28474 -- Made DurationField raise ValidationError for inputs that raised OverflowError.

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