Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#11042 closed (fixed)

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

Reported by: jsmullyan 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: UI/UX:

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 mir 5 years ago.
patch

Download all attachments as: .zip

Change History (7)

comment:1 Changed 5 years ago by mir

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to mir
  • Patch needs improvement unset

comment:2 Changed 5 years ago by mir

  • Component changed from Uncategorized to django.contrib.admin
  • milestone set to 1.1
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

verified that the bug is real

Changed 5 years ago by mir

patch

comment:3 Changed 5 years ago by mir

  • Has patch set
  • Needs tests unset
  • Owner mir 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?

comment:4 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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 Changed 5 years ago 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.

comment:6 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.