Opened 6 months ago
Last modified 6 months ago
#35548 assigned Bug
An error in TestCase.setUpTestData() leaks data on databases without transactions
Reported by: | Tim Graham | Owned by: | Rish |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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 (4)
comment:1 by , 6 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 6 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 6 months ago
Has patch: | set |
---|
comment:4 by , 6 months ago
Needs tests: | set |
---|
The PR lacks any tests. Perhaps inspiration could be taken from 0abb06930fc0686cb35079934e5bb40df66f5691.
Note:
See TracTickets
for help on using tickets.
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.