[Django] #36755: Example snippet for `models.RESTRICT` should be simplified.

10 views
Skip to first unread message

Django

unread,
Nov 24, 2025, 11:05:52 AM11/24/25
to django-...@googlegroups.com
#36755: Example snippet for `models.RESTRICT` should be simplified.
-------------------------------------+-------------------------------------
Reporter: Mads Hovvang | Type:
| Cleanup/optimization
Status: new | Component:
| Documentation
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Reading the example snippet for
[https://docs.djangoproject.com/en/5.2/ref/models/fields/#django.db.models.RESTRICT
`django.db.models.RESTRICT`], I had to go over the snippet a few times to
understand what was going on.

{{{#!python
>>> 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.

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

{{{#!python
>>> 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36755>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 24, 2025, 11:14:11 AM11/24/25
to django-...@googlegroups.com
#36755: Example snippet for `models.RESTRICT` should be simplified.
-------------------------------------+-------------------------------------
Reporter: Mads Hovvang | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mads Hovvang):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36755#comment:1>

Django

unread,
Nov 24, 2025, 11:25:37 AM11/24/25
to django-...@googlegroups.com
#36755: Example snippet for `models.RESTRICT` should be simplified.
-------------------------------------+-------------------------------------
Reporter: Mads Hovvang | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 5.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mads Hovvang):

* resolution: => invalid
* status: new => closed


Old description:
New description:

Reading the example snippet for
[https://docs.djangoproject.com/en/5.2/ref/models/fields/#django.db.models.RESTRICT
`django.db.models.RESTRICT`], I had to go over the snippet a few times to
understand what was going on.

{{{#!python
>>> 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`

{{{#!python
>>> 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.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36755#comment:2>

Django

unread,
Nov 24, 2025, 11:28:13 AM11/24/25
to django-...@googlegroups.com
#36755: Example snippet for `models.RESTRICT` should be simplified.
-------------------------------------+-------------------------------------
Reporter: Mads H | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 5.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mads H):

The multiple artists did serve a purpose in the example snippet not
covered in my example.
--
Ticket URL: <https://code.djangoproject.com/ticket/36755#comment:3>
Reply all
Reply to author
Forward
0 new messages