#37386 closed Bug (fixed)
Inconsistent treatment of 0 by ModelAdmin.delete_confirmation_max_display attribute
| Reported by: | Jacob Walls | Owned by: | Jacob Walls |
|---|---|---|---|
| Component: | contrib.admin | Version: | 6.1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Karolis Ryselis | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
ModelAdmin.delete_confirmation_max_display was added first in #10919 (6.1), and it treated zero as "show no objects" about to be deleted.
It was then adapted for a very similar use for inlines in #36984 (6.1), but the treatment of 0 was flipped from "show none" to "show all".
We had an explicit test over the template response for the former case confirming "no objects shown", but the flipped logic still caused some over-processing under the hood. Then, for inlines, 0 now means the opposite ("show all").
Opening a PR with a unit test shortly.
Change History (14)
comment:1 by , 3 weeks ago
| Has patch: | set |
|---|---|
| Needs tests: | unset |
comment:2 by , 3 weeks ago
| Description: | modified (diff) |
|---|
comment:3 by , 3 weeks ago
| Patch needs improvement: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Reproduced while doing the PR review.
comment:4 by , 3 weeks ago
| Patch needs improvement: | unset |
|---|
comment:5 by , 3 weeks ago
| Patch needs improvement: | set |
|---|
Jacob and I agreed to add a new minimal string to avoid having a sentence finished with a colon.
follow-up: 7 comment:6 by , 3 weeks ago
| Patch needs improvement: | unset |
|---|
Indeed, we did agree on that earlier today, however, I'm back to my original hesitation. The release-process.txt says:
The release candidate marks the string freeze ... After this point, new translatable strings must not be added.
During the 6.0.x series, we fixed a bug in a string in 05a5244b8924c47cc5b1332dd15aaa1be6abbe1e, but was a bug in a string that manifested 100% of the time, not a new string. Here we are contemplating a new string just to fix a dangling colon in an edge case. I don't think that qualifies for a backport. I don't think it's worth announcing a call for translations on the forum.
When targeting main only, we could also take the opportunity to address the dangling colon for top-level deletes as well. I'm pretty sure we have the same problem in that template:
-
django/contrib/admin/templates/admin/delete_selected_confirmation.html
diff --git a/django/contrib/admin/templates/admin/delete_selected_confirmation.html b/django/contrib/admin/templates/admin/delete_selected_confirmation.html index cf503ec123..e8ee7917ad 100644
a b 23 23 <p>{% blocktranslate %}Deleting the selected {{ objects_name }} would result in deleting related objects, but your account doesn't have permission to delete the following types of objects:{% endblocktranslate %}</p> 24 24 <ul>{{ perms_lacking|truncated_unordered_list:delete_confirmation_max_display }}</ul> 25 25 {% elif protected %} 26 <p>{% blocktranslate %}Deleting the selected {{ objects_name }} would require deleting the following protected related objects:{% endblocktranslate %}</p> 27 <ul>{{ protected|truncated_unordered_list:delete_confirmation_max_display }}</ul> 26 {% if delete_confirmation_max_display == 0 %} 27 <p>{% blocktranslate %}Deleting the selected {{ objects_name }} would require deleting some protected related objects.{% endblocktranslate %}</p> 28 {% else %} 29 <p>{% blocktranslate %}Deleting the selected {{ objects_name }} would require deleting the following protected related objects:{% endblocktranslate %}</p> 30 <ul>{{ protected|truncated_unordered_list:delete_confirmation_max_display }}</ul> 31 {% endif %} 28 32 {% else %} 29 33 <p>{% blocktranslate %}Are you sure you want to delete the selected {{ objects_name }}? All of the following objects and their related items will be deleted:{% endblocktranslate %}</p> 30 34 {% include "admin/includes/object_delete_summary.html" %}
And the {% if delete_confirmation_max_display is None or delete_confirmation_max_display > 0 %} I asked for in review only made it into one of the two relevant templates, so that also needs a fix, but again, IMO it's a "cleanup", not a "backportable bug in a new feature":
-
django/contrib/admin/templates/admin/delete_selected_confirmation.html
diff --git a/django/contrib/admin/templates/admin/delete_selected_confirmation.html b/django/contrib/admin/templates/admin/delete_selected_confirmation.html index cf503ec123..2d03114d68 100644
a b 28 28 {% else %} 29 29 <p>{% blocktranslate %}Are you sure you want to delete the selected {{ objects_name }}? All of the following objects and their related items will be deleted:{% endblocktranslate %}</p> 30 30 {% include "admin/includes/object_delete_summary.html" %} 31 {% if delete_confirmation_max_display is None or delete_confirmation_max_display > 0 %} 31 32 <h2>{% translate "Objects" %}</h2> 32 33 {% for deletable_object in deletable_objects %} 33 34 <ul>{{ deletable_object|truncated_unordered_list:delete_confirmation_max_display }}</ul> 34 35 {% endfor %} 36 {% endif %} 35 37 <form method="post">{% csrf_token %} 36 38 <div> 37 39 {% for obj in queryset %}
How does that full picture strike you?
comment:7 by , 3 weeks ago
Replying to Jacob Walls:
How does that full picture strike you?
Thanks for the detailed write up, I don't object to the plan for 6.1 (except a note in the next sentence), but I don't see why this can't all happen in the PR for this ticket though, as two commits: the first one with the current fix (and I'd argue also adding the missing guard in delete_selected_confirmation.html too, since it adds no strings and is a visible bug in a new 6.1 feature), which gets backported; and a second "Refs" commit with the new strings for the inline and both templates, since delete_confirmation.html has the same dangling colon, main only.
Locally I get:
<div id="content" class="colM">
<div class="titles-and-tools">
<div class="titles">
<h1>Cannot delete loooooooooooooooooooooooooooooooooooooooooooooooooooooong</h1>
</div>
</div>
<p>Deleting the loooooooooooooooooooooooooooooooooooooooooooooooooooooong “Repro 37386” would require deleting the following protected related objects:</p>
<ul id="deleted-objects"></ul>
<br class="clear">
</div>
Thoughts?
comment:8 by , 3 weeks ago
| Easy pickings: | unset |
|---|---|
| Patch needs improvement: | set |
Spot on. Sounds like a plan!
comment:9 by , 3 weeks ago
| Patch needs improvement: | unset |
|---|
comment:10 by , 2 weeks ago
| Patch needs improvement: | set |
|---|
comment:11 by , 2 weeks ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
PR