#27272: Protected objects not deleted even if they would have been deleted via
cascade anyway
----------------------------------+--------------------
Reporter: Daniel Izquierdo | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/27272>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.c1dc57095e73bf85c862d26bd32f4d3e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.