[Django] #32376: Allow destroy_test_db not to fail if database doesn't exist

8 views
Skip to first unread message

Django

unread,
Jan 21, 2021, 12:01:34 PM1/21/21
to django-...@googlegroups.com
#32376: Allow destroy_test_db not to fail if database doesn't exist
---------------------------------------------+------------------------
Reporter: Mateusz Mandera | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 3.1
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 |
---------------------------------------------+------------------------
**The situation**
In our test setup we directly call `connection.creation.destroy_test_db`
and the database that's meant to be dropped may or may not exist - the
latter scenario is completely okay and shouldn't fail

**The Problem**
_destroy_test_db uses `DROP DATABASE` query, meaning an exception is
thrown if the database doesn't exist

**A possible solution**
destroy_test_db could take an additional optional argument, which if True,
would cause `IF EXISTS` to be used in the query.

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

Django

unread,
Jan 22, 2021, 1:12:19 AM1/22/21
to django-...@googlegroups.com
#32376: Allow destroy_test_db() not to fail if database doesn't exist
-------------------------------------+-------------------------------------

Reporter: Mateusz Mandera | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: wontfix

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

* status: new => closed
* resolution: => wontfix
* component: Testing framework => Database layer (models, ORM)


Comment:

> In our test setup we directly call `connection.creation.destroy_test_db`
and the database that's meant to be dropped may or may not exist - the
latter scenario is completely okay and shouldn't fail

It's really unexpected that the database that you want to destroy doesn't
exist, so an exception is desired. You can always handle it in your app,
add a small wrapper, or
[https://docs.djangoproject.com/en/3.1/ref/databases/#subclassing-the-
built-in-database-backends subclass the built-in database backends].

> destroy_test_db could take an additional optional argument, which if
True, would cause IF EXISTS to be used in the query.

This would require a separate logic on SQLite and Oracle, I don't think
it's worth additional complexity. You can start a discussion on
DevelopersMailingList if you don't agree.

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

Reply all
Reply to author
Forward
0 new messages