Re: [Django] #12118: in-memory test database does not work with threads

32 views
Skip to first unread message

Django

unread,
Feb 11, 2014, 3:11:36 PM2/11/14
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.1
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: threads | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anonymous):

* status: closed => new
* severity: => Normal
* type: => Uncategorized
* easy: => 0
* ui_ux: => 0
* resolution: invalid =>


Comment:

I vote to reopen this.

sqlite, as of version 3.7.13 (released 2012-06-11) has the ability to
share an in-memory database between multiple connections and threads.

See: http://www.sqlite.org/releaselog/3_7_13.html

Making this work with the Django testing framework should be pretty easy:

In the sqlite database backend, instead of using the database name
`:memory:`, we should use a name such as
`file:testdb?mode=memory&cache=shared` (where "testdb" can be anything and
ideally should be unique so that multiple tests can run concurrently, each
with its own individual database).

As a bonus, doing this should allow removing the hacky sqlite-specific
code from "LiveServerTestCase" (It contains a messy workaround for exactly
the issue of this bug report)

The only thing that might be a little tricky is making this update in the
Django code to still support older vesions of sqlite by falling back to
the current behavior (`:memory:`), but I imagine that this shouldn't be
too difficult.

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

Django

unread,
Mar 20, 2014, 1:56:22 PM3/20/14
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.1
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: threads | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Alex):

* stage: Unreviewed => Accepted


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

Django

unread,
Mar 25, 2014, 7:44:10 AM3/25/14
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master

(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: threads | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* version: 1.1 => master
* type: Uncategorized => New feature


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

Django

unread,
Dec 1, 2014, 5:05:50 PM12/1/14
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: assigned

Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: threads | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by coldmind):

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


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

Django

unread,
Dec 8, 2014, 10:49:00 AM12/8/14
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: threads | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0

Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by coldmind):

* has_patch: 0 => 1


Comment:

Pull request here: https://github.com/django/django/pull/3677

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

Django

unread,
Dec 25, 2014, 2:00:32 PM12/25/14
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: threads | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


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

Django

unread,
Dec 30, 2014, 10:16:50 AM12/30/14
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: threads | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"8c99b7920e8187f98cf4d7dbd9918bd6c6da1238"]:
{{{
#!CommitTicketReference repository=""
revision="8c99b7920e8187f98cf4d7dbd9918bd6c6da1238"
Fixed #12118 -- Added shared cache support to SQLite in-memory testing.
}}}

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

Django

unread,
Sep 19, 2015, 11:57:13 AM9/19/15
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: threads | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by hjwp):

Incidentally, in case it's of use to anyone else that's temporarily stuck
on an earlier versions of django, you can hack a workaround for this by
using a path in `/dev/shm` in `TEST_NAME`:


{{{
DATABASES['default']['TEST_NAME'] = '/dev/shm/myproject-
djangotestdb.sqlite'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/12118#comment:9>

Django

unread,
Oct 6, 2015, 12:33:17 PM10/6/15
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: threads | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"3543fec3b739864c52de0a116dde3b0e5e885799" 3543fec3]:
{{{
#!CommitTicketReference repository=""
revision="3543fec3b739864c52de0a116dde3b0e5e885799"
Refs #12118 -- Allowed "mode=memory" in SQLite test database names.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/12118#comment:10>

Django

unread,
Oct 6, 2015, 12:34:20 PM10/6/15
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: threads | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"6f653f759ac2ba735bf8fa3fbb634a431288c041" 6f653f75]:
{{{
#!CommitTicketReference repository=""
revision="6f653f759ac2ba735bf8fa3fbb634a431288c041"
[1.9.x] Refs #12118 -- Allowed "mode=memory" in SQLite test database
names.

Backport of 3543fec3b739864c52de0a116dde3b0e5e885799 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/12118#comment:11>

Django

unread,
Oct 6, 2015, 12:34:24 PM10/6/15
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: coldmind
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: threads | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"e2db171e15b8d7d924cc4b1e0c67c96478c2644b" e2db171e]:
{{{
#!CommitTicketReference repository=""
revision="e2db171e15b8d7d924cc4b1e0c67c96478c2644b"
[1.8.x] Refs #12118 -- Allowed "mode=memory" in SQLite test database
names.

Backport of 3543fec3b739864c52de0a116dde3b0e5e885799 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/12118#comment:12>

Django

unread,
Oct 8, 2020, 6:56:02 AM10/8/20
to django-...@googlegroups.com
#12118: in-memory test database does not work with threads
-------------------------------------+-------------------------------------
Reporter: bluebird75 | Owner: Andriy
| Sokolovskiy

Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: threads | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

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


Comment:

Please don't reopen old tickets. You can create a new ticket, but Django
1.11 is no longer supported so you need to first confirm this issue in
Django 3.1+.

--
Ticket URL: <https://code.djangoproject.com/ticket/12118#comment:14>

Reply all
Reply to author
Forward
0 new messages