[Django] #29717: Provide a way for tests to run on an existing empty DB

14 views
Skip to first unread message

Django

unread,
Aug 28, 2018, 5:49:38 AM8/28/18
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis | Owner: nobody
Maloney |
Type: New | Status: new
feature |
Component: Database | Version: 2.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 1 | Needs tests: 1
Patch needs improvement: 1 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Periodically users ask in IRC for help running tests when the user they
connect as can not create a DB.

The reasons for this situation tend to be their DBA won't allow it, or
their corporate policy doesn't permit it.

Regardless, Django fails because when not using keepdb, it attempts to
create the db _always_, and only catches "duplicate DB name" errors to
indicate it already exists.

However, Postgres checks for CREATE DB permissions _before_ checking if
the DB exists, so Django sees it as a generic "DB creation problem" and
bails.

If we, instead, used the existing function [used by the keepdb logic] to
test if the DB exists, we could smooth the path for users in the above
situation.

I've started a patch which is currently _very_ wrong, and is awaiting
feedback as requested on the django-dev mailing list.

https://github.com/django/django/pull/10349

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

Django

unread,
Aug 28, 2018, 8:26:19 AM8/28/18
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

As I said on [https://groups.google.com/d/topic/django-developers/AF-
5K4atdF4/discussion django-developers], I don't see why we couldn't
recommend `--keepdb` for this use case?

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

Django

unread,
Aug 28, 2018, 9:14:41 PM8/28/18
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Curtis Maloney):

To clarify...

Basically, I want to separate create/drop of the DB with create/drop of
the objects within the DB, where currently we conflate the concepts.

Currently we have "must create db" vs. "may reuse db"

So we allow "must create db" which implies "must start clean"
We can do "may reuse db", but that currently forces "may reuse objects".

I'm trying to enable "may reuse db" with "must start clean".

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

Django

unread,
Aug 29, 2018, 2:08:54 PM8/29/18
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


Comment:

Thanks for clarifying. Maybe the Oracle-specific
[https://docs.djangoproject.com/en/dev/ref/settings/#create-db CREATE_DB]
setting in DATABASES 'OPTIONS' does what you want to do for PostgreSQL?
Possibly that might just be another way to do "keepdb" -- I didn't
investigate enough to confirm.

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

Django

unread,
Aug 29, 2018, 8:53:10 PM8/29/18
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Curtis Maloney):

Replying to [comment:3 Tim Graham]:


> Thanks for clarifying. Maybe the Oracle-specific
[https://docs.djangoproject.com/en/dev/ref/settings/#create-db CREATE_DB]
setting in DATABASES 'OPTIONS' does what you want to do for PostgreSQL?
Possibly that might just be another way to do "keepdb" -- I didn't
investigate enough to confirm.
>

From the docs:
{{{
If it is set to False, the test tablespaces won’t be automatically created
at the beginning of the tests or dropped at the end.
}}}

This is _close_ to what I was after. However, I'd want it to create and
tear down the models, etc.

So really we want to build a matrix of steps:

1. (a) Create DB --OR-- (b) Clear DB
1. Apply migrations
1. Revert migrations
1. Drop DB

Normally we affect all steps, with 3 implied by 4. Using --keepdb skips 3
and 4. I'm looking for a way to allow only 1(b), 2, and 3.

My current solution to step 3 is excessive, in that it will drop
_everything_, not just the objects we created in migrations. I don't
believe there is currently a simple way to migrate everything to ZERO,
instead we'd likely need to iterate the installed apps and do them
individually.

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

Django

unread,
Sep 4, 2023, 11:52:59 AM9/4/23
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Saarthak Maini):

* status: new => closed
* resolution: => wontfix


Comment:

Thank you for reporting the ticket.

As the ticket has been inactive for about 5 years, it would be suitable to
close the same.

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

Django

unread,
Sep 4, 2023, 1:48:51 PM9/4/23
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: nobody
Type: New feature | Status: new

Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

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

* status: closed => new
* resolution: wontfix =>


Comment:

Saarthak, we don't close tickets just because they are old.

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

Django

unread,
Mar 12, 2024, 3:23:20 AM3/12/24
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ülgen Sarıkavak):

* cc: Ülgen Sarıkavak (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/29717#comment:7>

Django

unread,
Feb 3, 2025, 10:30:47 AMFeb 3
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: Harsh
| Gautam
Type: New feature | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Harsh Gautam):

* owner: nobody => Harsh Gautam
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/29717#comment:8>

Django

unread,
Feb 6, 2025, 12:46:57 PMFeb 6
to django-...@googlegroups.com
#29717: Provide a way for tests to run on an existing empty DB
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by harshgautam5678):

* owner: Harsh Gautam => (none)
* status: assigned => new

--
Ticket URL: <https://code.djangoproject.com/ticket/29717#comment:9>
Reply all
Reply to author
Forward
0 new messages