diff options
| author | Julien Phalip <jphalip@gmail.com> | 2012-01-02 21:30:47 +0000 |
|---|---|---|
| committer | Julien Phalip <jphalip@gmail.com> | 2012-01-02 21:30:47 +0000 |
| commit | 31b1cbc623c246570e7301c0334df938d840638f (patch) | |
| tree | 979d3c9a4ed5454d628bb7a9fdffe1b9e517a9db /tests | |
| parent | fc9e0606d5333fc1906c85cc7ac3b2020e0b1baa (diff) | |
Fixed #16340 -- Made `get_or_create()` re-raise any `IntegrityError` with its original traceback. Thanks to d0ugal and Jonas Obrist.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17333 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/get_or_create/tests.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py index 4cf44507c8..f98f0e63d8 100644 --- a/tests/modeltests/get_or_create/tests.py +++ b/tests/modeltests/get_or_create/tests.py @@ -1,6 +1,7 @@ from __future__ import absolute_import from datetime import date +import traceback from django.db import IntegrityError from django.test import TestCase @@ -52,3 +53,14 @@ class GetOrCreateTests(TestCase): ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different" ) self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original") + + # get_or_create should raise IntegrityErrors with the full traceback. + # This is tested by checking that a known method call is in the traceback. + # We cannot use assertRaises/assertRaises here because we need to inspect + # the actual traceback. Refs #16340. + try: + ManualPrimaryKeyTest.objects.get_or_create(id=1, data="Different") + except IntegrityError, e: + formatted_traceback = traceback.format_exc() + self.assertIn('obj.save', formatted_traceback) + |
