Opened 3 weeks ago
Closed 3 weeks ago
#35979 closed Uncategorized (invalid)
Empty form ErrorList display as square brackets "[]"
Reported by: | Benjamin Mampaey | Owned by: | |
---|---|---|---|
Component: | Forms | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | yes |
Description
This is probably not a Django bug, it does not appear when running Django with manage.py runserver, but appears when running django with apache2 and some versions of mod_wsgi. I believe it should be made public so that if other people stumble on that problem, they know how to fix it.
In the admin templates, when forms are displayed, if there are no errors, there is a pair of square brackets above the label. For example in the login form, it shows a pair of square brackets above the label "Username".
From what I could find, mod_wsgi uses sub interpreters, and in version below 2.12.5 there is a bug where the MRO for __str__ is not properly done https://mliezun.github.io/2024/08/19/cpython-subinterpreters.html.
In the admin template, form errors are displayed using the __str__ method, for example in the login template, for the Username field :
<div class="form-row"> {{ form.username.errors }} {{ form.username.label_tag }} {{ form.username }} </div>
And the definition of ErrorList is
class ErrorList(UserList, list, RenderableErrorMixin)
Thus, because of the bug, when calling the __str__ method of ErrorList, instead of calling the __str__ method of RenderableErrorMixin, that returns an empty string , it is the __str__ method of list that is called that returns '[]'.
Thank you Benjamin, this ticket will keep a record
Since the goal of this issue tracker is to track issues about Django itself, I'll be closing this ticket as invalid following the ticket triaging process.
If, after debugging, you find out that this is a bug in Django, please re-open with the specific details and please be sure to include a small Django project to reproduce or a failing test case.