﻿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
12382	Deleting an inline can delete the whole inlined model instance recursively	Dirk Eschler	nobody	"A deleted inline can delete the whole inlined model (and all its related ForeignKeys) if the inlined model has a ForeignKey back to model it inlines. As this is best illustrated by an example, here's some code:

models.py:
{{{
class Telephone(models.Model):
    TELEPHONE_TYPES = ( ('WORK', 'Work'),
                        ('HOME', 'Home'),
                      )
    telephone_type = models.CharField(max_length=16, choices=TELEPHONE_TYPES)
    number = models.CharField(max_length=100)
    contact = models.ForeignKey('Contact')
    # ...

class Contact(models.Model):
    family_name = models.CharField(max_length=255, null=True, blank=True)
    given_name = models.CharField(max_length=255, null=True, blank=True)
    # ...
    preferred_telephone = models.ForeignKey(Telephone, related_name='preferred_telephone', null=True, blank=True)
}}}    

admin.py:
{{{
from

class TelephoneInline(admin.TabularInline):
    model = Telephone

class TelephoneAdmin(admin.ModelAdmin):
    # ...
    
class ContactAdmin(admin.ModelAdmin):
    # ...
    inlines = [
        TelephoneInline,
    ]
}}}

Steps:

 * Create a contact with a telephone number through the admin and save it
 * Choose the new telephone number as preferred_telephone and save the contact
 * Check the delete checkbox for the telephone number
 * Save

Expected:

The telephone number is deleted.

Result:

The contact is deleted recursively! In addition a 404 is raised that the contact doesn't exist, which is true.

If the Contact model had more relations, like a ForeignKey relation to an Address model for instance, all the addresses of the contact would have been deleted, too.

"	Bug	new	contrib.admin	1.1	Normal		admin inlines	eschler@… bugs@… Carsten Fuchs	Accepted	0	0	0	0	0	1
