Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23857 closed Bug (fixed)

"Save as new" breaks when related inlines are marked to be deleted

Reported by: Alex Marandon Owned by: nobody
Component: contrib.admin Version: 1.7
Severity: Release blocker Keywords:
Cc: jonathan.morgan@…, jonathan.morgan.007@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Minimal project that triggers the issue:

# model.py
from django.db import models


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

    def __unicode__(self):
        return self.name


class Book(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)

    def __unicode__(self):
        return self.title
# admin.py
from django.contrib import admin
from .models import Author, Book


class AuthorshipInline(admin.TabularInline):
    model = Book.authors.through


@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
    inlines = [AuthorshipInline]
    save_as = True


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    inlines = [AuthorshipInline]
    save_as = True

How to reproduce the problem using the admin:

  • create two authors
  • create a book with those two authors
  • edit the book
  • click the check box in the "Delete?" column for one of the authors
  • click "Save as new"

Tail of the stack trace:

File "/home/synext/lib/python2.7/site-packages/Django-1.7.1-py2.7.egg/django/db/models/deletion.py" in collect
  168.                             reverse_dependency=reverse_dependency)
File "/home/synext/lib/python2.7/site-packages/Django-1.7.1-py2.7.egg/django/db/models/deletion.py" in add
  85.             if obj not in instances:
File "/home/synext/lib/python2.7/site-packages/Django-1.7.1-py2.7.egg/django/db/models/base.py" in __hash__
  485.             raise TypeError("Model instances without primary key value are unhashable")

Exception Type: TypeError at /admin/myapp/book/1/
Exception Value: Model instances without primary key value are unhashable

Change History (5)

comment:1 by Jonathan Morgan, 10 years ago

Cc: jonathan.morgan.007@… added

comment:2 by Tim Graham, 10 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

I could reproduce this by adding save_as=True to PollAdmin from the tutorial and then repeating the steps above. It appears to be a regression in 1.7, probably due to 6af05e7a0f0e4604d6a67899acaa99d73ec0dfaa.

comment:3 by Tim Graham, 10 years ago

Has patch: set

comment:4 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In c7a19f42030c15ad3b3475ad9a4854e10733ff74:

Fixed #23857 -- Fixed admin crash with "save as new" and deleting inline.

Thanks amarandon for the report.

comment:5 by Tim Graham <timograham@…>, 10 years ago

In c64286c62b5960387d5e8fc3e28cd37662bda6cb:

[1.7.x] Fixed #23857 -- Fixed admin crash with "save as new" and deleting inline.

Thanks amarandon for the report.

Backport of c7a19f42030c15ad3b3475ad9a4854e10733ff74 from master

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