Opened 3 weeks ago
Closed 3 weeks ago
#36942 closed Bug (needsinfo)
SimpleTestCase._remove_databases_failures() is not idempotent and crashes on complex MRO.
| 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: | yes | 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.
Attachments (1)
Change History (3)
by , 3 weeks ago
| Attachment: | check_mro.py added |
|---|
comment:1 by , 3 weeks ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 weeks ago
| Needs tests: | set |
|---|---|
| Resolution: | → needsinfo |
| Status: | assigned → closed |
Hi Michele,
Thanks for the report. Seems reasonable, but without a example to play with it's a little hard to QA it. Could you provide an example class hierarchy that produces the issue? Happy to take another look then.