[Django] #36984: Prevent extremely long validation messages in inlines

16 views
Skip to first unread message

Django

unread,
Mar 13, 2026, 7:27:15 AMMar 13
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: esperonus-karolis | Type:
| Uncategorized
Status: new | Component:
| contrib.admin
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Currently Django inlines generate a DeleteProtectedModelForm with
`hand_clean_DELETE` that validates for protected items. If the amount of
protected items is large, the error message is huge as all protected
objects are listed. The message spanning thousands of entries is
impossible to read as is not structured, and nobody is going to check
thousands of items manually either. An image showing what it looks like
(excuse my locale of the message): [[Image(https://ibb.co/4RKCK5Nb)]]

Therefore, I propose to limit the amount of protected items shown in
inline validation, listing at most N items where N is subject to a
discussion, and then adding "and X more" to indicate that the list is not
extensive.

Here is a rough idea on how this could be implemented:

{{{
def hand_clean_DELETE(self):
"""
We don't validate the 'DELETE' field itself because on
templates it's not rendered using the field information, but
just using a generic "deletion_field" of the InlineModelAdmin.
"""
if self.cleaned_data.get(DELETION_FIELD_NAME, False):
using = router.db_for_write(self._meta.model)
collector = NestedObjects(using=using)
if self.instance._state.adding:
return
collector.collect([self.instance])
if collector.protected:
objs = []
for p in collector.protected[:MAX_VALIDATION_OUTPUT_ITEMS]:
objs.append(
# Translators: Model verbose name and instance
# representation, suitable to be an item in a
# list.
_("%(class_name)s %(instance)s")
% {"class_name": p._meta.verbose_name, "instance": p}
)
params = {
"class_name": self._meta.model._meta.verbose_name,
"instance": self.instance,
}
if len(collector.protected) > MAX_VALIDATION_OUTPUT_ITEMS:
params['related_objects'] = get_text_list(objs, _(", ")) +
_(' and %d more') % (len(collector.protected) -
MAX_VALIDATION_OUTPUT_ITEMS)
else:
params['related_objects'] = get_text_list(objs, _(" and
"))
msg = _(
"Deleting %(class_name)s %(instance)s would require "
"deleting the following protected related objects: "
"%(related_objects)s"
)
raise ValidationError(
msg, code="deleting_protected", params=params
)
}}}

If everyone is happy about this, I could implement the change.
--
Ticket URL: <https://code.djangoproject.com/ticket/36984>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 18, 2026, 2:26:59 PMMar 18
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: Karolis Ryselis | Owner: Karolis
Type: | Ryselis
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* owner: (none) => Karolis Ryselis
* stage: Unreviewed => Accepted
* status: new => assigned
* type: Uncategorized => Cleanup/optimization

Comment:

Thanks, this is similar in spirit to #10919. Thanks for offering a PR as
well.
--
Ticket URL: <https://code.djangoproject.com/ticket/36984#comment:1>

Django

unread,
Mar 19, 2026, 3:51:26 AMMar 19
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: Karolis Ryselis | Owner: Karolis
Type: | Ryselis
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Karolis Ryselis):

* has_patch: 0 => 1

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

Django

unread,
Mar 20, 2026, 3:39:39 AMMar 20
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: Karolis Ryselis | Owner: Karolis
Type: | Ryselis
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Karolis Ryselis):

I have created a pull request:
[https://github.com/django/django/pull/20945]
--
Ticket URL: <https://code.djangoproject.com/ticket/36984#comment:3>

Django

unread,
Apr 23, 2026, 9:19:53 AMApr 23
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: Karolis Ryselis | Owner: Karolis
Type: | Ryselis
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36984#comment:4>

Django

unread,
Jun 5, 2026, 4:01:29 PM (16 hours ago) Jun 5
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: Karolis Ryselis | Owner: Karolis
Type: | Ryselis
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

Comment:

Plan to backport to 6.1, as once we decided to consolidate with the
approach in #10919, we
[https://github.com/django/django/pull/20945#discussion_r3149033919
realized] it was already suggested in the documentation that this worked
for inlines as well. So instead of editing the docs for 6.1, and moving
the cheese in 6.2, we can just implement the missing feature and ship
something more complete.
--
Ticket URL: <https://code.djangoproject.com/ticket/36984#comment:5>

Django

unread,
Jun 5, 2026, 5:10:14 PM (15 hours ago) Jun 5
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: Karolis Ryselis | Owner: Karolis
Type: | Ryselis
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"57c8c8b107248a3358dd26276ac497c577454011" 57c8c8b1]:
{{{#!CommitTicketReference repository=""
revision="57c8c8b107248a3358dd26276ac497c577454011"
Fixed #36984 -- Made inline formset error messages respect
delete_confirmation_max_display.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36984#comment:6>

Django

unread,
Jun 5, 2026, 5:11:41 PM (15 hours ago) Jun 5
to django-...@googlegroups.com
#36984: Prevent extremely long validation messages in inlines
-------------------------------------+-------------------------------------
Reporter: Karolis Ryselis | Owner: Karolis
Type: | Ryselis
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"16093e38b03ff448d3eb784c44a7f7020d25d4bf" 16093e38]:
{{{#!CommitTicketReference repository=""
revision="16093e38b03ff448d3eb784c44a7f7020d25d4bf"
[6.1.x] Fixed #36984 -- Made inline formset error messages respect
delete_confirmation_max_display.

Backport of 57c8c8b107248a3358dd26276ac497c577454011 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36984#comment:7>
Reply all
Reply to author
Forward
0 new messages