Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#11042 closed (fixed)

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

Reported by: Jacob Smullyan Owned by:
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (1)

mir-11042.diff (645 bytes ) - added by Michael Radziej 16 years ago.
patch

Download all attachments as: .zip

Change History (7)

comment:1 by Michael Radziej, 16 years ago

Owner: changed from nobody to Michael Radziej

comment:2 by Michael Radziej, 16 years ago

Component: Uncategorizeddjango.contrib.admin
milestone: 1.1
Needs tests: set
Triage Stage: UnreviewedAccepted

verified that the bug is real

by Michael Radziej, 16 years ago

Attachment: mir-11042.diff added

patch

comment:3 by Michael Radziej, 16 years ago

Has patch: set
Needs tests: unset
Owner: Michael Radziej removed

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?

comment:4 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: newclosed

(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.

comment:5 by Russell Keith-Magee, 16 years ago

(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.

comment:6 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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