Django

Code

Ticket #11042 (closed: fixed)

Opened 11 months ago

Last modified 11 months ago

admin inlines of inherited models break on edit submit after changeset 10666

Reported by: jsmullyan Assigned to:
Milestone: 1.1 Component: django.contrib.admin
Version: 1.0 Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

after r10666, an inline of an inherited model cannot be edited. The following traceback results upon submit:

Traceback:
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/contrib/admin/options.py" in wrapper
  226.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/contrib/admin/sites.py" in inner
  184.             return view(request, *args, **kwargs)
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/db/transaction.py" in _commit_on_success
  240.                 res = func(*args, **kw)
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/contrib/admin/options.py" in change_view
  832.                     self.save_formset(request, form, formset, change=True)
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/contrib/admin/options.py" in save_formset
  563.         formset.save()
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/forms/models.py" in save
  509.         return self.save_existing_objects(commit) + self.save_new_objects(commit)
File "/home/smulloni/.virtualenvs/jangle/lib/python2.5/site-packages/django/forms/models.py" in save_existing_objects
  615.             pk_value = form.fields[pk_name].clean(raw_pk_value).pk

Exception Type: AttributeError at /admin/bobapp/bob/1/
Exception Value: 'NoneType' object has no attribute 'pk'

Reverse-merging r10666 makes the problem go away.

The trivial example code to reproduce the bug:

# models.py
from django.db import models

class Bob(models.Model):
    name=models.CharField(max_length=100)

class Thing(models.Model):
    name=models.CharField(max_length=100)

class FancyThing(Thing):
    is_fancy=models.BooleanField(default=True)
    bob=models.ForeignKey(Bob)


#admin.py
from django.contrib import admin

from models import FancyThing, Bob

class FancyThingInline(admin.StackedInline):
    model=FancyThing

class BobAdmin(admin.ModelAdmin):
    inlines=[FancyThingInline]

admin.site.register(Bob, BobAdmin)

Attachments

mir-11042.diff (0.6 kB) - added by mir on 05/08/09 12:25:12.
patch

Change History

05/08/09 08:37:33 changed by mir

  • owner changed from nobody to mir.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

05/08/09 09:34:39 changed by mir

  • stage changed from Unreviewed to Accepted.
  • component changed from Uncategorized to django.contrib.admin.
  • needs_tests set to 1.
  • milestone set to 1.1.

verified that the bug is real

05/08/09 12:25:12 changed by mir

  • attachment mir-11042.diff added.

patch

05/08/09 12:27:40 changed by mir

  • owner deleted.
  • has_patch set to 1.
  • needs_tests deleted.

This is really a bug introduced in [10666] that broke using subclassed models in admin inlines. #11042

The changeset introduced a function has_auto_field that checked for auto pk fields instead of checking whether it has been automatically created.

I'm not so familiar with this area, can someone please review it?

05/09/09 06:40:14 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [10725]) Fixed #11042 -- Corrected admin inlines for inherited models. Thanks to jsmullyan for the report, and mir for helpful triage work. Patch includes regression test for #8093, and a commented out test for #10992.

05/09/09 06:52:15 changed by russellm

(In [10726]) [1.0.X] Fixed #11042 -- Corrected admin inlines for inherited models. Thanks to jsmullyan for the report, and mir for helpful triage work. Patch includes regression test for #8093, and a commented out test for #10992.

Merge of r10725 from trunk.


Add/Change #11042 (admin inlines of inherited models break on edit submit after changeset 10666)




Change Properties
Action