﻿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
27272	Add a on_delete RESTRICT handler to allow cascading deletions while protecting direct ones	Daniel Izquierdo	Daniel Izquierdo	"Consider this set of models:

{{{
#!python
class Artist(models.Model):
    name = models.CharField(max_length=10)

class Album(models.Model):
    artist = models.ForeignKey(Artist, on_delete=models.CASCADE)

class Song(models.Model):
    artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
    album = models.ForeignKey(Album, on_delete=models.PROTECT)
}}}

And the following test:


{{{
#!python
class TestDeletion(TestCase):
    def test_delete(self):
        artist = Artist.objects.create(name='test')
        album = Album.objects.create(artist=artist)
        Song.objects.create(artist=artist, album=album)

        artist.delete()
}}}

What is the expected result of the test?

Currently, this test fails with ProtectedError raised, because trying to delete the artist results in trying to delete the album, which is protected because of the related song. But, the related song was going to be deleted anyway, via the cascading relationship to the artist itself. So I believe that deletion should succeed in this particular case.

If there's agreement that the current behavior is a bug, I'll work on a fix.

Mailing list discussion (no replies so far): https://groups.google.com/forum/#!topic/django-users/xEe4D5VHRnY"	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed		Simon Charette	Ready for checkin	1	0	0	0	0	0
