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
}}}
{{{
#!python
# 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:
{{{
#!pytb
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23857>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: jonathan.morgan.007@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23857#comment:1>
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23857#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/3682 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/23857#comment:3>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"c7a19f42030c15ad3b3475ad9a4854e10733ff74"]:
{{{
#!CommitTicketReference repository=""
revision="c7a19f42030c15ad3b3475ad9a4854e10733ff74"
Fixed #23857 -- Fixed admin crash with "save as new" and deleting inline.
Thanks amarandon for the report.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23857#comment:4>
Comment (by Tim Graham <timograham@…>):
In [changeset:"c64286c62b5960387d5e8fc3e28cd37662bda6cb"]:
{{{
#!CommitTicketReference repository=""
revision="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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23857#comment:5>