[Django] #25860: Test setup error: Cannot operate on a closed database

16 views
Skip to first unread message

Django

unread,
Dec 3, 2015, 10:48:55 AM12/3/15
to django-...@googlegroups.com
#25860: Test setup error: Cannot operate on a closed database
-----------------------------------+------------------------
Reporter: jonashaag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords: regression
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------
Coming from https://groups.google.com/forum/#!topic/django-
developers/t1xaSmNMuKQ, I found a bug in the test database setup. This is
probably related to #24080 but I'm not 100% sure.

The error can be shown with a specific series of skipped and non-skipped
tests. I attached a minimal example project that demonstrates the issue.

This used to work in Django 1.7, and doesn't work in any Django versions
later than 1.7. It is caused, according to a Git bisect, by
https://github.com/django/django/commit/da9fe5c717c179a9e881a40efd3bfe36a21bf4a6.

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

Django

unread,
Dec 3, 2015, 10:49:16 AM12/3/15
to django-...@googlegroups.com
#25860: Test setup error: Cannot operate on a closed database
-------------------------------+----------------------------

Reporter: jonashaag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:

Keywords: regression | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------+----------------------------
Changes (by jonashaag):

* Attachment "t.tar.bz2" added.

Minimal test project

Django

unread,
Dec 3, 2015, 11:01:32 AM12/3/15
to django-...@googlegroups.com
#25860: Test setup error: Cannot operate on a closed database
-----------------------------------+--------------------------------------

Reporter: jonashaag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:

Keywords: regression | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

If you raise `SkipTest` in `setUpClass()` after calling `super()`, then
I'd think the database setup in `TestCase.setUpClass()` happens but not
the teardown in `TestCase.tearDownClass`? If so, I'm not sure there's much
Django can do about the issue. Any suggestions? Can you raise `SkipTest`
before calling `super()`?

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

Django

unread,
Dec 3, 2015, 11:06:34 AM12/3/15
to django-...@googlegroups.com
#25860: Test setup error: Cannot operate on a closed database
-----------------------------------+--------------------------------------

Reporter: jonashaag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:

Keywords: regression | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by carljm):

Without digging into it more I don't know if this is something that would
need to be fixed in Django or in stdlib unittest, but ISTM that ideally
even if `SkipTest` is raised after `setUpClass`, the testing framework
ought to be responsible to make sure that `tearDownClass` is still called
regardless.

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

Django

unread,
Dec 4, 2015, 6:13:22 AM12/4/15
to django-...@googlegroups.com
#25860: Test setup error: Cannot operate on a closed database
-----------------------------------+--------------------------------------

Reporter: jonashaag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:

Keywords: regression | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by jonashaag):

I agree with carljm.

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

Django

unread,
Dec 4, 2015, 6:21:40 AM12/4/15
to django-...@googlegroups.com
#25860: Test setup error: Cannot operate on a closed database
-----------------------------------+--------------------------------------

Reporter: jonashaag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:

Keywords: regression | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by jonashaag):

From the Python docs:

If an exception is raised during a setUpClass then the tests in the class
are not run **and the tearDownClass is not run**. Skipped classes will not
have setUpClass or tearDownClass run. If the exception is a SkipTest
exception then the class will be reported as having been skipped instead
of as an error.

Looks like nothing's wrong with Django here.

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

Django

unread,
Dec 5, 2015, 5:51:13 PM12/5/15
to django-...@googlegroups.com
#25860: Document transaction leak possiblity in TestCase
--------------------------------------+------------------------------------
Reporter: jonashaag | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
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 timgraham):

* keywords: regression =>
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
* component: Testing framework => Documentation


Comment:

How about a [https://github.com/django/django/pull/5777 documentation
patch] to raise awareness?

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

Django

unread,
Dec 7, 2015, 6:33:54 PM12/7/15
to django-...@googlegroups.com
#25860: Document transaction leak possiblity in TestCase
--------------------------------------+------------------------------------
Reporter: jonashaag | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"a5619f7ed3bc2ca07b428fa0abfaaff088378f48" a5619f7e]:
{{{
#!CommitTicketReference repository=""
revision="a5619f7ed3bc2ca07b428fa0abfaaff088378f48"
Fixed #25860 -- Documented a transaction leak possiblity in TestCase.

Thanks Jonas Haag for report and review.
}}}

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

Django

unread,
Dec 7, 2015, 6:34:12 PM12/7/15
to django-...@googlegroups.com
#25860: Document transaction leak possiblity in TestCase
--------------------------------------+------------------------------------
Reporter: jonashaag | Owner: nobody

Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
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 Tim Graham <timograham@…>):

In [changeset:"35b5e11a98580e5f5045be36e8901699e39d2867" 35b5e11]:
{{{
#!CommitTicketReference repository=""
revision="35b5e11a98580e5f5045be36e8901699e39d2867"
[1.9.x] Fixed #25860 -- Documented a transaction leak possiblity in
TestCase.

Thanks Jonas Haag for report and review.

Backport of a5619f7ed3bc2ca07b428fa0abfaaff088378f48 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages