#8719: KeyError on save of model with inline-edited ForeignKey with non-standard
primary key
-----------------------------+----------------------------------------------
 Reporter:  jonloyens        |       Owner:  nobody    
   Status:  new              |   Milestone:            
Component:  Admin interface  |     Version:  SVN       
 Keywords:                   |       Stage:  Unreviewed
Has_patch:  0                |  
-----------------------------+----------------------------------------------
 When editing a ForeignKey relationship inline in admin, if the model
 representing the foreign key has a non-standard primary key, a KeyError
 will be thrown when editing an existing model.

 Consider the following models and admin classes:

 {{{
 class ModelA( models.Model )
     some_data = models.CharField(max_length=255, blank=True)

 class ModelB( models.Model ):
     mypk_id = models.AutoField(primary_key=True)
     modela = models.ForeignKey(ModelA)
     more_data = models.CharField(max_length=255, blank=True)

 class ModelBAdmin( admin.StackedInline ):
     model = ModelB

 class ModelAAdmin( admin.ModelAdmin ):
      inlines = [ModelBAdmin]
 }}}

 When attempting to save an existing ModelA in admin with an existing
 ModelB.  Admin will throw a KeyError due to there not being a 'mypk_id' in
 the cleaned_data of the FormSet here:

 {{{
 Environment:

 Request Method: POST
 Request URL: http://localhost:8000/admin/auth/user/12922/
 Django Version: 1.0-beta_2-SVN-8706
 Python Version: 2.5.1
 Installed Applications:
 ['django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.sites',
  'mc_billing_site.billing',
  'django.contrib.admin']
 Installed Middleware:
 ('django.middleware.common.CommonMiddleware',
  'django.contrib.sessions.middleware.SessionMiddleware',
  'django.contrib.auth.middleware.AuthenticationMiddleware',
  'django.middleware.doc.XViewMiddleware')


 Traceback:
 File "/Library/Python/2.5/site-packages/django/core/handlers/base.py" in
 get_response
   86.                 response = callback(request, *callback_args,
 **callback_kwargs)
 File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in
 root
   173.                 return self.model_page(request, *url.split('/', 2))
 File "/Library/Python/2.5/site-packages/django/views/decorators/cache.py"
 in _wrapped_view_func
   44.         response = view_func(request, *args, **kwargs)
 File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in
 model_page
   192.         return admin_obj(request, rest_of_url)
 File "/Library/Python/2.5/site-packages/django/contrib/auth/admin.py" in
 __call__
   42.         return super(UserAdmin, self).__call__(request, url)
 File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py"
 in __call__
   196.             return self.change_view(request, unquote(url))
 File "/Library/Python/2.5/site-packages/django/db/transaction.py" in
 _commit_on_success
   238.                 res = func(*args, **kw)
 File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py"
 in change_view
   588.                     self.save_formset(request, form, formset,
 change=True)
 File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py"
 in save_formset
   378.         formset.save()
 File "/Library/Python/2.5/site-packages/django/forms/models.py" in save
   280.         return self.save_existing_objects(commit) +
 self.save_new_objects(commit)
 File "/Library/Python/2.5/site-packages/django/forms/models.py" in
 save_existing_objects
   294.             obj =
 existing_objects[form.cleaned_data[self.model._meta.pk.attname]]

 Exception Type: KeyError at /admin/testapp/modela/12922/
 Exception Value: 'mypk_id'
 }}}

 I am absolutely conviced this is related to this other ticket:
 [http://code.djangoproject.com/ticket/8695 8695] but want to make sure
 this gets tested as well.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8719>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to