#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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019c6fffdc41-f3a32911-091e-40e3-88fd-8499c3c8fc8b-000000%40eu-central-1.amazonses.com.

Reply via email to