Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23674 closed Bug (fixed)

form.changed_data breaks on invalid intial data.

Reported by: Florian Apolloner Owned by: Grzegorz Ślusarek
Component: Forms Version: 1.7
Severity: Normal Keywords:
Cc: Florian Apolloner 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

Traceback from the admin after the following steps (came up in IRC today):

  • Open http://localhost:8000/admin/auth/user/1/
  • Change "date joined" to an invalid date
  • Hit "save and continue editing" -- a normal form error is shown
  • Change the date back to a valid value and hit save
  • Get greeted by the following traceback:
    Environment:
    
    
    Request Method: POST
    Request URL: http://localhost:8000/admin/auth/user/1/
    
    Django Version: 1.8.dev20141015153619
    Python Version: 2.7.8
    Installed Applications:
    ('django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles')
    Installed Middleware:
    ('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',
     'django.middleware.security.SecurityMiddleware')
    
    
    Traceback:
    File "/home/florian/sources/django.git/django/core/handlers/base.py" in get_response
      125.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/florian/sources/django.git/django/contrib/admin/options.py" in wrapper
      602.                 return self.admin_site.admin_view(view)(*args, **kwargs)
    File "/home/florian/sources/django.git/django/utils/decorators.py" in _wrapped_view
      110.                     response = view_func(request, *args, **kwargs)
    File "/home/florian/sources/django.git/django/views/decorators/cache.py" in _wrapped_view_func
      54.         response = view_func(request, *args, **kwargs)
    File "/home/florian/sources/django.git/django/contrib/admin/sites.py" in inner
      212.             return view(request, *args, **kwargs)
    File "/home/florian/sources/django.git/django/contrib/admin/options.py" in change_view
      1477.         return self.changeform_view(request, object_id, form_url, extra_context)
    File "/home/florian/sources/django.git/django/utils/decorators.py" in _wrapper
      34.             return bound_func(*args, **kwargs)
    File "/home/florian/sources/django.git/django/utils/decorators.py" in _wrapped_view
      110.                     response = view_func(request, *args, **kwargs)
    File "/home/florian/sources/django.git/django/utils/decorators.py" in bound_func
      30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
    File "/home/florian/sources/django.git/django/utils/decorators.py" in inner
      145.                     return func(*args, **kwargs)
    File "/home/florian/sources/django.git/django/contrib/admin/options.py" in changeform_view
      1431.                     change_message = self.construct_change_message(request, form, formsets)
    File "/home/florian/sources/django.git/django/contrib/admin/options.py" in construct_change_message
      1006.         if form.changed_data:
    File "/home/florian/sources/django.git/django/forms/forms.py" in changed_data
      462.                 if field.has_changed(initial_value, data_value):
    File "/home/florian/sources/django.git/django/forms/fields.py" in has_changed
      1104.             if field.has_changed(field.to_python(initial), data):
    File "/home/florian/sources/django.git/django/forms/fields.py" in to_python
      483.         return super(TimeField, self).to_python(value)
    File "/home/florian/sources/django.git/django/forms/fields.py" in to_python
      437.         raise ValidationError(self.error_messages['invalid'], code='invalid')
    
    Exception Type: ValidationError at /admin/auth/user/1/
    Exception Value: [u'Enter a valid time.']
    
    

Change History (9)

comment:1 by Baptiste Mispelon, 10 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Interestingly, there is no error when you do the same procedure with the "last login" field.

comment:2 by Grzegorz Ślusarek, 10 years ago

Owner: changed from nobody to Grzegorz Ślusarek
Status: newassigned

comment:3 by Grzegorz Ślusarek, 10 years ago

Has patch: set

comment:4 by Florian Apolloner, 10 years ago

Patch needs improvement: set

Commented on the PR

comment:5 by Grzegorz Ślusarek, 10 years ago

comment:6 by Grzegorz Ślusarek, 10 years ago

Patch needs improvement: unset

comment:7 by Tim Graham, 10 years ago

Triage Stage: AcceptedReady for checkin

Not sure if this is a regression, but since it's a crashing issue, we can probably add release notes and backport to 1.7.

comment:8 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 0dea81cd6d34b3e41cc4bbec99b5fdf06142b09e:

Fixed #23674 -- Fixed a crash when a MultiValueField has invalid data.

comment:9 by Tim Graham <timograham@…>, 10 years ago

In 4b96e862b4674e85d1a28f2849685aa3135bc557:

[1.7.x] Fixed #23674 -- Fixed a crash when a MultiValueField has invalid data.

Backport of 0dea81cd6d34b3e41cc4bbec99b5fdf06142b09e from master

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