Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tested that get_or_create raises IntegrityError.

It used to raise "DatabaseError: no such savepoint" with the old
transaction management. Closes #15117.
  • Loading branch information...
commit 3a4276ffc35326f20e95890b50a67aebeabc9ad0 1 parent 90fe914
@aaugustin aaugustin authored
Showing with 19 additions and 2 deletions.
  1. +4 −0 tests/get_or_create/models.py
  2. +15 −2 tests/get_or_create/tests.py
View
4 tests/get_or_create/models.py
@@ -24,3 +24,7 @@ def __str__(self):
class ManualPrimaryKeyTest(models.Model):
id = models.IntegerField(primary_key=True)
data = models.CharField(max_length=100)
+
+
+class Profile(models.Model):
+ person = models.ForeignKey(Person, primary_key=True)
View
17 tests/get_or_create/tests.py
@@ -4,9 +4,9 @@
import traceback
from django.db import IntegrityError
-from django.test import TestCase
+from django.test import TestCase, TransactionTestCase
-from .models import Person, ManualPrimaryKeyTest
+from .models import Person, ManualPrimaryKeyTest, Profile
class GetOrCreateTests(TestCase):
@@ -64,3 +64,16 @@ def test_get_or_create(self):
formatted_traceback = traceback.format_exc()
self.assertIn('obj.save', formatted_traceback)
+
+class GetOrCreateTransactionTests(TransactionTestCase):
+
+ def test_get_or_create_integrityerror(self):
+ # Regression test for #15117. Requires a TransactionTestCase on
+ # databases that delay integrity checks until the end of transactions,
+ # otherwise the exception is never raised.
+ try:
+ Profile.objects.get_or_create(person=Person(id=1))
+ except IntegrityError:
+ pass
+ else:
+ self.skipTest("This backend does not support integrity checks.")
Please sign in to comment.
Something went wrong with that request. Please try again.