Opened 7 hours ago
Last modified 7 hours ago
#36942 assigned Bug
SimpleTestCase._remove_databases_failures() is not idempotent and crashes on complex MRO. — at Version 1
| Reported by: | Michele Fiori | Owned by: | michele0303 |
|---|---|---|---|
| Component: | Testing framework | Version: | 6.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Michele Fiori | Triage Stage: | Unreviewed |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When using complex test inheritance (e.g., mixing multiple LiveServerTestCase subclasses or dynamic test class generation), the cleanup method
_remove_databases_failures can be called in a state where database connection methods have already been unwrapped or were never wrapped for a specific alias.
Currently, the code assumes the wrapped attribute always exists: setattr(connection, name, method.wrapped)
This leads to an AttributeError: 'function' object has no attribute 'wrapped'.
The proposed fix adds a defensive hasattr(method, "wrapped") check to make the teardown process idempotent and robust against complex class hierarchies.
Change History (2)
by , 7 hours ago
| Attachment: | check_mro.py added |
|---|
comment:1 by , 7 hours ago
| Description: | modified (diff) |
|---|