[Django] #36359: id_for_label undefined for AdminReadonlyField

2 views
Skip to first unread message

Django

unread,
Apr 29, 2025, 9:07:39 AM4/29/25
to django-...@googlegroups.com
#36359: id_for_label undefined for AdminReadonlyField
-------------------------------------+-------------------------------------
Reporter: Marc Sommerhalder | Type: Bug
Status: new | Component:
| contrib.admin
Version: 5.2 | 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
-------------------------------------+-------------------------------------
AdminReadonlyField does not define `id_for_label`
([https://github.com/django/django/blob/65bbdbd10b25700d1166b1a698e672a4695281bc/django/contrib/admin/helpers.py#L225
here]) but uses it when `help_text` is present
([https://github.com/django/django/blob/65bbdbd10b25700d1166b1a698e672a4695281bc/django/contrib/admin/templates/admin/includes/fieldset.html#L29
here]).
--
Ticket URL: <https://code.djangoproject.com/ticket/36359>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 29, 2025, 1:29:16 PM4/29/25
to django-...@googlegroups.com
#36359: id_for_label undefined for AdminReadonlyField
-----------------------------------+--------------------------------------
Reporter: Marc Sommerhalder | Owner: (none)
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Natalia Bidart):

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

Comment:

Hello Marc Sommerhalder, thanks for taking the time to report this and for
referencing the relevant code.

You're correct that `AdminReadonlyField` does not define `id_for_label`.
However, from what I can see, it's only accessed conditionally (i.e. only
if it's already defined) so there doesn’t appear to be any resulting error
or broken behavior in the admin output:
{{{
{% if field.field.id_for_label %} id="{{ field.field.id_for_label
}}_helptext"{% endif %}
}}}

To better understand the problem you're experiencing, could you clarify
what concrete issue you're observing in practice? For example, is there a
traceback, rendering problem, or integration issue that this is causing?
That would help determine whether this needs a code change or if the
current behavior is acceptable.

I'll close as `invalid` for now but please reopen if you can provide
further details (ideally a test case failing or a small Django test
project to reproduce the error or the issue you are getting). You can also
reach out in the Django Forum for further assistance
--
Ticket URL: <https://code.djangoproject.com/ticket/36359#comment:1>

Django

unread,
Feb 18, 2026, 4:06:12 AM (yesterday) Feb 18
to django-...@googlegroups.com
#36359: id_for_label undefined for AdminReadonlyField
-----------------------------------+--------------------------------------
Reporter: Marc Sommerhalder | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Lukas Klimas):

* cc: Lukas Klimas (added)
* resolution: invalid =>
* status: closed => new

Comment:

AdminReadonlyField missing `id_for_label` definition creates a lot of log
messages with big stacktraces of `AttributeError: 'dict' object has no
attribute 'id_for_label'` or `KeyError: 'id_for_label' `.
In my case, project (Django 4.2) had `structlog` library for logging,
which had rich traceback formatting enabled for the messages, thus
creating big performance issues for admin pages. Example: with default
implementation pages loaded in 2 seconds, with patched code it takes
600ms.

Patch applied from:
{{{
{% if field.field.help_text %}
<div class="help"{% if field.field.id_for_label %}
id="{{ field.field.id_for_label }}_helptext"{% endif %}>
<div>{{ field.field.help_text|safe }}</div>
</div>
{% endif %}
}}}
to:
{{{
{% if field.field.help_text %}
<div class="help"{% if not field.is_readonly and
field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{%
endif %}>
<div>{{ field.field.help_text|safe }}</div>
</div>
{% endif %}
}}}

These log messages were logged under `DEBUG` level, thus changing the log
level could also help.

To reproduce the problem requires:
1. Model with the field, that has defined `help_text` parameter.
2. Admin page for that model, that describes this field as `readonly`
--
Ticket URL: <https://code.djangoproject.com/ticket/36359#comment:2>
Reply all
Reply to author
Forward
0 new messages