[Django] #20316: TestCase will let code rollback and commit without warning

7 views
Skip to first unread message

Django

unread,
Apr 24, 2013, 12:21:05 PM4/24/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-----------------------------------+--------------------
Reporter: uberj@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
The docs for
[https://docs.djangoproject.com/en/1.3/topics/testing/#django.test.TransactionTestCase
TransactionTestCase] say `TestCase` "prevents the code under test from
issuing any commit or rollback operations on the database". Code running
in a `TestCase` that uses `commit` or `rollback` will still ''appear'' to
work. Of course, those functions don't do anything, they have been
replaced by a `nop` function that silently does nothing -- see
[https://github.com/django/django/blob/master/django/test/testcases.py#L75
here].

The 'silently' part does not help a user that is using `TestCase` but
should be using `TransactionTestCase`.

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

Django

unread,
Apr 24, 2013, 12:27:32 PM4/24/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-----------------------------------+--------------------------------------

Reporter: uberj@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 1.4
Severity: Normal | Resolution:
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 uberj@…):

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


Comment:

In a perfect world, I would like to see at least one of the following
happen:
* `nop` raise an exception warning the user that they should be using
`TransactionTestCase`
* A print statement warning the user
* The docs on `TransactionTestCase` updated to not use the word
'prevents', and mention something about how functions like `commit` and
`rollback` are essentially callable nops when used in a `TestCase`.

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

Django

unread,
Apr 24, 2013, 12:44:54 PM4/24/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-------------------------------------+-------------------------------------
Reporter: uberj@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: Documentation | Resolution:
Severity: Normal | Triage Stage:
Keywords: testcase | Unreviewed
transactions | Needs documentation: 1
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by charettes):

* component: Testing framework => Documentation
* version: 1.4 => master
* easy: 0 => 1
* keywords: => testcase transactions
* needs_docs: 0 => 1
* type: Uncategorized => Cleanup/optimization


Comment:

Unfortunately first and second options are no-go since there's no reliable
way to differentiate implicit from explicit `commit` and `rollback` calls.

i.e. You'd like explicit `transaction.commit` call to raise an exception
or a warning but not the implicit calls from `Model().save()`.

It would also be highly backward incompatible.

Third option seems reasonable, a documentation patch is welcome!

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

Django

unread,
Apr 29, 2013, 1:30:51 PM4/29/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-------------------------------------+-------------------------------------
Reporter: uberj@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: master
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: testcase | Needs documentation: 1
transactions | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by timo):

* stage: Unreviewed => Accepted


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

Django

unread,
May 19, 2013, 4:29:54 AM5/19/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-------------------------------------+-------------------------------------
Reporter: uberj@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: master
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: testcase | Needs documentation: 1
transactions | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

I've changed the docs, basically restating what the ticket author has
already said.
patch at:
https://github.com/lolek09/django/commit/2df87c45496bf7a9e2da109ffee20d50b40af042.patch
graphic diff:
https://github.com/lolek09/django/commit/2df87c45496bf7a9e2da109ffee20d50b40af042

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

Django

unread,
May 23, 2013, 9:53:55 AM5/23/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-------------------------------------+-------------------------------------
Reporter: uberj@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: master
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: testcase | Needs documentation: 1
transactions | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0

Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by timo):

* has_patch: 0 => 1


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

Django

unread,
May 23, 2013, 11:11:19 AM5/23/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-------------------------------------+-------------------------------------
Reporter: uberj@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: master
Component: Documentation | Resolution: fixed

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

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


Comment:

In [changeset:"dffdca1109a2111f104f2419d081c0f971537fec"]:
{{{
#!CommitTicketReference repository=""
revision="dffdca1109a2111f104f2419d081c0f971537fec"
Fixed #20316 - Clarified transaction behavior of TestCase.

Thanks uberj@ for the report and lolek09 for the patch.
}}}

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

Django

unread,
May 23, 2013, 11:13:28 AM5/23/13
to django-...@googlegroups.com
#20316: TestCase will let code rollback and commit without warning
-------------------------------------+-------------------------------------
Reporter: uberj@… | Owner: nobody

Type: | Status: closed
Cleanup/optimization | Version: master
Component: Documentation | Resolution: fixed
Severity: Normal | Triage Stage: Accepted
Keywords: testcase | Needs documentation: 1
transactions | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

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

In [changeset:"cd15a51c3eb2918107814e7c42533ebef982a431"]:
{{{
#!CommitTicketReference repository=""
revision="cd15a51c3eb2918107814e7c42533ebef982a431"
[1.5.x] Fixed #20316 - Clarified transaction behavior of TestCase.

Thanks uberj@ for the report and lolek09 for the patch.

Backport of dffdca1109 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages