Opened 83 minutes ago

Closed 64 minutes ago

Last modified 61 minutes ago

#36755 closed Cleanup/optimization (invalid)

Example snippet for `models.RESTRICT` should be simplified.

Reported by: Mads H Owned by:
Component: Documentation Version: 5.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Mads H)

Reading the example snippet for `django.db.models.RESTRICT`, I had to go over the snippet a few times to understand what was going on.

>>> artist_one = Artist.objects.create(name="artist one")
>>> artist_two = Artist.objects.create(name="artist two")
>>> album_one = Album.objects.create(artist=artist_one)
>>> album_two = Album.objects.create(artist=artist_two)
>>> song_one = Song.objects.create(artist=artist_one, album=album_one)
>>> song_two = Song.objects.create(artist=artist_one, album=album_two)
>>> album_one.delete()
# Raises RestrictedError.
>>> artist_two.delete()
# Raises RestrictedError.
>>> artist_one.delete()
(4, {'Song': 2, 'Album': 1, 'Artist': 1})

Why are there multiple artists, albums and songs in this example? They don't impact the example in any meaningful way.

And deleting artist_two doesn't

After some testing, I figure this snippet demonstrates the same capabilities of models.RESTRICT

>>> artist = Artist.objects.create(name="artist one")
>>> album = Album.objects.create(artist=artist)
>>> song = Song.objects.create(artist=artist, album=album)
>>> album.delete()
# Raises RestrictedError.
>>> artist.delete()
(4, {"Album": 1, "Artist": 1, "Song": 1})

Sorry if this is a bit much for such a simple change, but the github checklist explicitly states anything but a typo fix needs a trac ID.

Change History (3)

comment:1 by Mads H, 75 minutes ago

Has patch: set

comment:2 by Mads H, 64 minutes ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

comment:3 by Mads H, 61 minutes ago

The multiple artists did serve a purpose in the example snippet not covered in my example.

Note: See TracTickets for help on using tickets.
Back to Top