Opened 17 years ago

Closed 17 years ago

#3684 closed (duplicate)

IndexError in Field.get_manipulator_new_data with related fields

Reported by: imbaczek@… Owned by: Adrian Holovaty
Component: contrib.admin Version: dev
Severity: 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

Traceback (most recent call last):
File "/home/imbaczek/usr/django-trunk/django/core/handlers/base.py" in get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "/home/imbaczek/usr/django-trunk/django/contrib/admin/views/decorators.py" in _checklogin
  55. return view_func(request, *args, **kwargs)
File "/home/imbaczek/usr/django-trunk/django/views/decorators/cache.py" in _wrapped_view_func
  39. response = view_func(request, *args, **kwargs)
File "/home/imbaczek/usr/django-trunk/django/contrib/admin/views/main.py" in add_stage
  254. new_object = manipulator.save(new_data)
File "/home/imbaczek/usr/django-trunk/django/db/models/manipulators.py" in save
  172. if f.core and not isinstance(f, FileField) and f.get_manipulator_new_data(rel_new_data, rel=True) in (None, ''):
File "/home/imbaczek/usr/django-trunk/django/db/models/fields/__init__.py" in get_manipulator_new_data
  288. return new_data.get(self.name, [self.get_default()])[0]

  IndexError at /admin/articles/article/add/
  string index out of range

The root of the problem seems to be that related field's new_data dict is not a MultiValueDict, but a more-or-less usual dict (probably originating from a DotExpandedDict.) This causes all sorts of b0rkage when editing inline related models. A patch that fixes IndexError when the field in question is blank and makes strings as they were passed and not only first letter, though it's probably not correct. The problem exists on the dev server, haven't tried mod_python or anything else.

Index: __init__.py
===================================================================
--- __init__.py (wersja 4685)
+++ __init__.py (kopia robocza)
@@ -285,7 +285,7 @@
         field's data.
         """
         if rel:
-            return new_data.get(self.name, [self.get_default()])[0]
+            return new_data.get(self.name, [self.get_default()])
         val = new_data.get(self.name, self.get_default())
         if not self.empty_strings_allowed and val == '' and self.null:
             val = None

Change History (1)

comment:1 by Malcolm Tredinnick, 17 years ago

Resolution: duplicate
Status: newclosed

Seems to be agreed that this is a dupe of #3765 and the root cause is being diagnosed over there.

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