Opened 2 years ago

Closed 2 years ago

#33278 closed Cleanup/optimization (fixed)

Use a custom exception type with django.test.testcases._DatabaseFailure

Reported by: Daniel Hahler Owned by: SwastikTripathi
Component: Testing framework Version: 3.2
Severity: Normal Keywords:
Cc: Simon Charette Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently an AssertionError with a message is used in case of blocked DB operations:

class _DatabaseFailure:
    def __init__(self, wrapped, message):
        self.wrapped = wrapped
        self.message = message

    def __call__(self):
        raise AssertionError(self.message)

(source)

Using a custom/distinctive exception type would allow for better catching and handling of this.
Currently you would have to parse its message and/or look at the stack trace to see if it's this specific error, or a "normal" assertion error from a test.

Change History (6)

comment:1 by Mariusz Felisiak, 2 years ago

Cc: Simon Charette added
Triage Stage: UnreviewedAccepted

Sounds reasonable, thanks.

comment:2 by Simon Charette, 2 years ago

Sounds reasonable to me as well, I assume we'll want to subclass AssertionError but a distinct type shouldn't hurt.

comment:3 by SwastikTripathi, 2 years ago

Owner: changed from nobody to SwastikTripathi
Status: newassigned

Yes we can surely do that. Here's my PR https://github.com/django/django/pull/15082

comment:4 by Mariusz Felisiak, 2 years ago

Has patch: set
Patch needs improvement: set

comment:5 by Mariusz Felisiak, 2 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 76f07b4f:

Fixed #33278 -- Improved error for connection/query attempts against disallowed databases in tests.

Note: See TracTickets for help on using tickets.
Back to Top