Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverse deleting forms cause Key Error #30

Open
elo80ka opened this issue Feb 27, 2014 · 0 comments
Open

reverse deleting forms cause Key Error #30

elo80ka opened this issue Feb 27, 2014 · 0 comments

Comments

@elo80ka
Copy link
Owner

elo80ka commented Feb 27, 2014

From kipan...@gmail.com on June 16, 2011 01:55:18

What steps will reproduce the problem? 1. Create 2 model formsets:

ParentFormSet = modelformset_factory(Parent, extra=1, can_delete=True, max_num=2)
GuardianFormSet = modelformset_factory(Guardian, extra=1, can_delete=True, max_num=10)

  1. Then if I have one instance of Guardian Form, add empty second form and instantly delete first, and then the second, thus having no forms, and press submit. What is the expected output? What do you see instead? Expected: Deletion of Guardian from DB and return of success template
    Got instead: Key error

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/iep_admin/add_student/5/

Django Version: 1.3
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.flatpages',
'django.contrib.staticfiles',
'django.contrib.webdesign',
'grappelli',
'django.contrib.admin',
'django.contrib.admindocs',
'uni_form',
'pagination',
'south',
'django_coverage',
'smart_selects',
'ajax_filtered_fields',
'ckeditor',
'countries',
'accounts',
'about',
'addresses',
'phones',
'languages',
'races',
'schools',
'persons',
'parents',
'guardians',
'students',
'employee',
'reports',
'iepachieve_app',
'note',
'transitions',
'dajaxice',
'iep_admin',
'iep_panel',
'task',
'meeting']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'pagination.middleware.PaginationMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')

Traceback:
File "/home/ki/Envs/iepachieve/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1.                     response = callback(request, _callback_args, *_callback_kwargs)
    
    File "/home/ki/code/iepachieve/apps/students/views.py" in add_student
  2.     guardian_formset = GuardianFormSet(request.POST, request.FILES, queryset=guardian_queryset, prefix='guardian')
    
    File "/home/ki/Envs/iepachieve/lib/python2.7/site-packages/django/forms/models.py" in init
  3.     super(BaseModelFormSet, self).**init**(**defaults)
    
    File "/home/ki/Envs/iepachieve/lib/python2.7/site-packages/django/forms/formsets.py" in init
  4.     self._construct_forms()
    
    File "/home/ki/Envs/iepachieve/lib/python2.7/site-packages/django/forms/formsets.py" in _construct_forms
  5.         self.forms.append(self._construct_form(i))
    
    File "/home/ki/Envs/iepachieve/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
  6.         pk = self.data[pk_key]
    
    File "/home/ki/Envs/iepachieve/lib/python2.7/site-packages/django/utils/datastructures.py" in getitem
  7.         raise MultiValueDictKeyError("Key %r not found in %r" % (key, self))
    

Exception Type: MultiValueDictKeyError at /iep_admin/add_student/5/
Exception Value: "Key 'guardian-0-id' not found in <QueryDict: {u'last_name': [u'Belvedersky'], u'classification': [u'ED'], u'grade': [u'2'], u'guardian-1-middle_name': [u''], u'parent-0-race': [u''], u'guardian-1-birth_date': [u'1983-07-06'], u'phone_numbers': [u'1152'], u'guardian-TOTAL_FORMS': [u'2'], u'first_name': [u'Appolon2'], u'parent-0-first_name': [u'Ki4'], u'middle_name': [u''], u'parent-0-language': [u''], u'guardian-INITIAL_FORMS': [u'1'], u'parent-0-last_name': [u'P'], u'csrfmiddlewaretoken': [u'b66057413251cd8b465fb72a6c87ce5a'], u'parent-0-id': [u'11'], u'parent-0-DELETE': [u''], u'parent-INITIAL_FORMS': [u'1'], u'parent-0-gender': [u'm'], u'parent-0-occupation': [u''], u'parent-MAX_NUM_FORMS': [u'2'], u'parent-0-middle_name': [u''], u'parent-0-birth_date': [u'1983-07-06'], u'guardian-1-occupation': [u''], u'guardian-1-last_name': [u'Last'], u'guardian-1-id': [u'17'], u'guardian-1-first_name': [u'Guadian7'], u'guardian-1-race': [u''], u'language': [u''], u'level': [u'2'], u'gender': [u'm'], u'guardian-1-gender': [u'm'], u'race': [u''], u'guardian-1-DELETE': [u'on'], u'parent-TOTAL_FORMS': [u'1'], u'birth_date': [u'2010-11-17'], u'guardian-1-language': [u''], u'guardian-MAX_NUM_FORMS': [u'10']}>"
**************** What version of the product are you using? On what operating system? Please provide any additional information below.

Original issue: http://code.google.com/p/django-dynamic-formset/issues/detail?id=30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant