[Django] #33278: Use a custom exception type with django.test.testcases._DatabaseFailure

5 views
Skip to first unread message

Django

unread,
Nov 10, 2021, 1:17:49 PM11/10/21
to django-...@googlegroups.com
#33278: Use a custom exception type with django.test.testcases._DatabaseFailure
------------------------------------------------+------------------------
Reporter: Daniel Hahler | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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)
}}}
([https://github.com/django/django/blob/dfa1145a22042dcf9e504a5a7edd5557e3e0d07c/django/test/testcases.py#L142-L148
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33278>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 10, 2021, 1:54:35 PM11/10/21
to django-...@googlegroups.com
#33278: Use a custom exception type with django.test.testcases._DatabaseFailure
--------------------------------------+------------------------------------

Reporter: Daniel Hahler | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* cc: Simon Charette (added)
* stage: Unreviewed => Accepted


Comment:

Sounds reasonable, thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/33278#comment:1>

Django

unread,
Nov 10, 2021, 2:27:15 PM11/10/21
to django-...@googlegroups.com
#33278: Use a custom exception type with django.test.testcases._DatabaseFailure
--------------------------------------+------------------------------------

Reporter: Daniel Hahler | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Simon Charette):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/33278#comment:2>

Django

unread,
Nov 12, 2021, 12:40:00 PM11/12/21
to django-...@googlegroups.com
#33278: Use a custom exception type with django.test.testcases._DatabaseFailure
-------------------------------------+-------------------------------------
Reporter: Daniel Hahler | Owner:
Type: | SwastikTripathi
Cleanup/optimization | Status: assigned

Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by SwastikTripathi):

* owner: nobody => SwastikTripathi
* status: new => assigned


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/33278#comment:3>

Django

unread,
Nov 12, 2021, 1:05:17 PM11/12/21
to django-...@googlegroups.com
#33278: Use a custom exception type with django.test.testcases._DatabaseFailure
-------------------------------------+-------------------------------------
Reporter: Daniel Hahler | Owner:
Type: | SwastikTripathi
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33278#comment:4>

Django

unread,
Nov 15, 2021, 6:01:16 AM11/15/21
to django-...@googlegroups.com
#33278: Use a custom exception type with django.test.testcases._DatabaseFailure
-------------------------------------+-------------------------------------
Reporter: Daniel Hahler | Owner:
Type: | SwastikTripathi
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33278#comment:5>

Django

unread,
Nov 15, 2021, 2:33:56 PM11/15/21
to django-...@googlegroups.com
#33278: Use a custom exception type with django.test.testcases._DatabaseFailure
-------------------------------------+-------------------------------------
Reporter: Daniel Hahler | Owner:
Type: | SwastikTripathi
Cleanup/optimization | Status: closed

Component: Testing framework | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"76f07b4fcfa570d194ee4ee8e20d56fd917998a7" 76f07b4f]:
{{{
#!CommitTicketReference repository=""
revision="76f07b4fcfa570d194ee4ee8e20d56fd917998a7"
Fixed #33278 -- Improved error for connection/query attempts against
disallowed databases in tests.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33278#comment:6>

Reply all
Reply to author
Forward
0 new messages