﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23857	"""Save as new"" breaks when related inlines are marked to be deleted"	Alex Marandon	nobody	"Minimal project that triggers the issue:
{{{
#!python
# 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
}}}

{{{
#!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
}}}"	Bug	closed	contrib.admin	1.7	Release blocker	fixed		jonathan.morgan@… jonathan.morgan.007@…	Accepted	1	0	0	0	0	0
