Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Aymeric Augustin authored April 28, 2013
4  tests/get_or_create/models.py
@@ -24,3 +24,7 @@ def __str__(self):
24 24
 class ManualPrimaryKeyTest(models.Model):
25 25
     id = models.IntegerField(primary_key=True)
26 26
     data = models.CharField(max_length=100)
  27
+
  28
+
  29
+class Profile(models.Model):
  30
+    person = models.ForeignKey(Person, primary_key=True)
17  tests/get_or_create/tests.py
@@ -4,9 +4,9 @@
4 4
 import traceback
5 5
 
6 6
 from django.db import IntegrityError
7  
-from django.test import TestCase
  7
+from django.test import TestCase, TransactionTestCase
8 8
 
9  
-from .models import Person, ManualPrimaryKeyTest
  9
+from .models import Person, ManualPrimaryKeyTest, Profile
10 10
 
11 11
 
12 12
 class GetOrCreateTests(TestCase):
@@ -64,3 +64,16 @@ def test_get_or_create(self):
64 64
             formatted_traceback = traceback.format_exc()
65 65
             self.assertIn('obj.save', formatted_traceback)
66 66
 
  67
+
  68
+class GetOrCreateTransactionTests(TransactionTestCase):
  69
+
  70
+    def test_get_or_create_integrityerror(self):
  71
+        # Regression test for #15117. Requires a TransactionTestCase on
  72
+        # databases that delay integrity checks until the end of transactions,
  73
+        # otherwise the exception is never raised.
  74
+        try:
  75
+            Profile.objects.get_or_create(person=Person(id=1))
  76
+        except IntegrityError:
  77
+            pass
  78
+        else:
  79
+            self.skipTest("This backend does not support integrity checks.")

0 notes on commit 3a4276f

Please sign in to comment.
Something went wrong with that request. Please try again.