#33346: Form rendering in Django 4 causes AttributeError during testing
---------------------------------------+------------------------
               Reporter:  OutOfFocus4  |          Owner:  nobody
                   Type:  Bug          |         Status:  new
              Component:  Forms        |        Version:  4.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            |
---------------------------------------+------------------------
 I started updating a project from Django 3 to Django 4. When I ran my unit
 tests after the update, one of them failed with an AttributeError.

 The full stack trace is

 {{{
 Traceback (most recent call last):
   File "/private/tmp/example/example/tests.py", line 17, in test_formset
     self.assertFormsetError(
   File "/private/tmp/example/.venv/lib/python3.9/site-
 packages/django/test/testcases.py", line 565, in assertFormsetError
     if field in context[formset].forms[form_index].errors:
 AttributeError: 'ManagementForm' object has no attribute 'forms'
 }}}

 It looks like rendering the ManagementForm of a formset adds a context to
 response.context which contains a "form". Calling "assertFormsetError" to
 check for errors in a formset called "form" will check the formset's
 errors, but will also try to look at the errors in any "form" in all
 contexts, including the ManagementForm.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33346>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/054.5c356cc512edd448f5df423df9bf1968%40djangoproject.com.

Reply via email to