#33346: assertFormsetError() crashes on formset named "form".
-----------------------------------+------------------------------------
     Reporter:  OutOfFocus4        |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  4.0
     Severity:  Release blocker    |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------

Comment (by Baptiste Mispelon):

 I did some digging around `assertFormsetError` (and `assertFormError`)
 while working on #33301 and came to the conclusion that they might be
 fundamentally broken.

 Both methods work by looking for a specific name in the context of
 **each** template rendered during the execution of the view. When the name
 is not found in the template, it is skipped. If the name is found then the
 `context[name]` object is checked for the assertion.

 The issue is that you cannot always control which templates are rendered
 during your views, and especially what names those templates are using in
 their respective contexts.
 The situation is even worse now that Django uses templates to render
 forms, formsets and widgets.

 Restricting the search to the first context would probably fix most issues
 like the one reported here, but it's not 100% correct (and backwards-
 incompatible).

 The only way out that I could think of would be to deprecate passing a
 `response` to `assertFormError`/`assertFormsetError` in favor of passing
 the form/formset object directly. I think it would be a more natural API
 anway (I never understood why the assertions were based on the response to
 begin with).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33346#comment:3>
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/069.06ea65e0b8e52d2e353d72d115762c06%40djangoproject.com.

Reply via email to