An error in TestCase.setUpTestData() leaks data on databases without transactions
While working on a backend for MongoDB, I found that an exception on the fourth line of expressions.tests.ExpressionsNumericTests.setUpTestData
left Number
rows in the database such that a later test failed like this:
======================================================================
ERROR: test_F_reuse (expressions.tests.ExpressionsTests.test_F_reuse)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tim/code/django/tests/expressions/tests.py", line 1217, in test_F_reuse
self.assertEqual(n_qs.get(), n)
^^^^^^^^^^
File "/home/tim/code/django/django/db/models/query.py", line 652, in get
raise self.model.MultipleObjectsReturned(
expressions.models.Number.MultipleObjectsReturned: get() returned more than one Number -- it returned more than 20!
This is the same problem as #25176 but for databases with DatabaseFeatures.supports_transactions = False
.
Change History
(6)
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to Rish
|
Status: |
new → assigned
|
Owner: |
Rish removed
|
Status: |
assigned → new
|
Needs tests: |
unset
|
Owner: |
set to JaeHyuckSa
|
Status: |
new → assigned
|
I think the following should do and also avoid a lack of rolling back transaction when they are supported
django/test/testcases.py
Only lightly tested though.