summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2011-12-09 23:16:56 +0000
committerAdrian Holovaty <adrian@holovaty.com>2011-12-09 23:16:56 +0000
commit073d987a84d7ebdf3b70789f22b8a12a9f5ae96f (patch)
tree68b8366679230f95e95d7f527b0ed752eeb4e563 /tests
parent594a45ed292d79901d45252603dc8e7a5d991d22 (diff)
Fixed #16818 -- Fixed ORM bug with many-to-many add() method where it wasn't committing the change. Thanks, pressureman and kmtracey
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17189 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/transactions_regress/models.py6
-rw-r--r--tests/regressiontests/transactions_regress/tests.py16
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/regressiontests/transactions_regress/models.py b/tests/regressiontests/transactions_regress/models.py
index 54e6f4f37b..e8bca8ada2 100644
--- a/tests/regressiontests/transactions_regress/models.py
+++ b/tests/regressiontests/transactions_regress/models.py
@@ -2,3 +2,9 @@ from django.db import models
class Mod(models.Model):
fld = models.IntegerField()
+
+class M2mA(models.Model):
+ others = models.ManyToManyField('M2mB')
+
+class M2mB(models.Model):
+ fld = models.IntegerField()
diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py
index 26ef4163e6..bdc1b53600 100644
--- a/tests/regressiontests/transactions_regress/tests.py
+++ b/tests/regressiontests/transactions_regress/tests.py
@@ -5,7 +5,7 @@ from django.db import connection, transaction
from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
from django.test import TransactionTestCase, skipUnlessDBFeature
-from .models import Mod
+from .models import Mod, M2mA, M2mB
class TestTransactionClosing(TransactionTestCase):
@@ -164,3 +164,17 @@ class TestTransactionClosing(TransactionTestCase):
_ = User.objects.all()[0]
except:
self.fail("A transaction consisting of a failed operation was not closed.")
+
+class TestManyToManyAddTransaction(TransactionTestCase):
+ def test_manyrelated_add_commit(self):
+ "Test for https://code.djangoproject.com/ticket/16818"
+ a = M2mA.objects.create()
+ b = M2mB.objects.create(fld=10)
+ a.others.add(b)
+
+ # We're in a TransactionTestCase and have not changed transaction
+ # behavior from default of "autocommit", so this rollback should not
+ # actually do anything. If it does in fact undo our add, that's a bug
+ # that the bulk insert was not auto-committed.
+ transaction.rollback()
+ self.assertEqual(a.others.count(), 1)