#23857: "Save as new" breaks when related inlines are marked to be deleted
-------------------------------+--------------------
     Reporter:  amarandon      |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  contrib.admin  |    Version:  1.7
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 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
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23857>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.0e56460273b978d9a618cebae918f872%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to