Opened 3 hours ago

Last modified 3 hours ago

#36942 assigned Bug

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: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Michele Fiori)

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.

PR: https://github.com/django/django/pull/20758

Attachments (1)

check_mro.py (705 bytes ) - added by Michele Fiori 3 hours ago.

Download all attachments as: .zip

Change History (2)

by Michele Fiori, 3 hours ago

Attachment: check_mro.py added

comment:1 by Michele Fiori, 3 hours ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top