#37064: SimpleTestCase._remove_databases_failures() crashes on un-wrapped
connection methods
-----------------------------------+--------------------------------------
     Reporter:  Rio Weber          |                    Owner:  (none)
         Type:  Bug                |                   Status:  closed
    Component:  Testing framework  |                  Version:  6.0
     Severity:  Normal             |               Resolution:  invalid
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  1                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Changes (by Natalia Bidart):

 * keywords:  testcase, databases, multi-db, regression =>
 * resolution:   => invalid
 * status:  new => closed

Comment:

 The premise of this ticket is that `_remove_databases_failures` should be
 defensive about state it itself established. That framing inverts the
 actual contract.

 `_add_databases_failures` and `_remove_databases_failures` are a symmetric
 setup/teardown pair. The setup installs a `_DatabaseFailure` wrapper on
 each disallowed connection method, the teardown removes it. The teardown's
 assumption that `.wrapped` exists **is not a fragility**: it is a direct
 consequence of the setup having run. If that attribute is missing,
 something replaced Django's wrapper without restoring the original, which
 is a bug ''in that code, not in Django''.

 The submitted PR confirm this. The test validates the case where a method
 has been swapped out from under Django without a proper restore, therefore
 proving the bug exists in the code doing the swapping, then asks Django to
 silently accommodate it. The proposed `isinstance` guard also makes
 teardown silently incomplete: if the invariant is broken, the original
 method is never restored. The connection is left in whatever unknown state
 the third-party code deposited. That failure mode is harder to debug than
 the current `AttributeError`, which at least points clearly at the code
 that broke the invariant.

 Closing as invalid. If a reproduction can be demonstrated with no third-
 party connection wrapping involved, and not connection mutation without
 proper restore, please reopen with a self-contained test case against a
 clean Django install.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37064#comment:23>
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/0107019dc74dbe46-80b3173d-60fb-4fa9-a548-df8c08985538-000000%40eu-central-1.amazonses.com.

Reply via email to