summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-02-14 09:57:31 -0500
committerTim Graham <timograham@gmail.com>2018-02-15 13:41:33 -0500
commit4b8e433e1cacd7405d6ae0a88d1776adc0068f10 (patch)
tree0556a61829479755674b65af055c9176c45b3c66 /tests
parentfd18345e10b9e5c9713c606509feaf18e57178e2 (diff)
[2.0.x] Fixed #29126 -- Doc'd the behavior of QuerySet.update_or_create() with manually specified pks.
Backport of e917ea6bec45d7f789ca96a13be15df9521963e1 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/get_or_create/tests.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/get_or_create/tests.py b/tests/get_or_create/tests.py
index 60e1ef23f2..1aed318608 100644
--- a/tests/get_or_create/tests.py
+++ b/tests/get_or_create/tests.py
@@ -444,6 +444,19 @@ class UpdateOrCreateTests(TestCase):
self.assertEqual(obj.last_name, 'NotHarrison')
+class UpdateOrCreateTestsWithManualPKs(TestCase):
+
+ def test_create_with_duplicate_primary_key(self):
+ """
+ If an existing primary key is specified with different values for other
+ fields, then IntegrityError is raised and data isn't updated.
+ """
+ ManualPrimaryKeyTest.objects.create(id=1, data='Original')
+ with self.assertRaises(IntegrityError):
+ ManualPrimaryKeyTest.objects.update_or_create(id=1, data='Different')
+ self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, 'Original')
+
+
class UpdateOrCreateTransactionTests(TransactionTestCase):
available_apps = ['get_or_create']