diff --git a/django/db/models/query.py b/django/db/models/query.py
index 6a6a829..cd474d7 100644
a
|
b
|
The main QuerySet implementation. This provides the public API for the ORM.
|
4 | 4 | |
5 | 5 | import copy |
6 | 6 | from itertools import izip |
| 7 | import sys |
7 | 8 | |
8 | 9 | from django.db import connections, router, transaction, IntegrityError |
9 | 10 | from django.db.models.aggregates import Aggregate |
… |
… |
class QuerySet(object):
|
387 | 388 | return obj, True |
388 | 389 | except IntegrityError, e: |
389 | 390 | transaction.savepoint_rollback(sid, using=self.db) |
| 391 | exc_info = sys.exc_info() |
390 | 392 | try: |
391 | 393 | return self.get(**lookup), False |
392 | 394 | except self.model.DoesNotExist: |
393 | | raise e |
| 395 | # re-raise the IntegrityError with the original traceback. |
| 396 | raise exc_info[1], None, exc_info[2] |
394 | 397 | |
395 | 398 | def latest(self, field_name=None): |
396 | 399 | """ |
diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py
index 3323c88..0eac405 100644
a
|
b
|
|
1 | 1 | from datetime import date |
| 2 | import sys |
| 3 | import traceback |
2 | 4 | |
3 | 5 | from django.db import IntegrityError |
4 | 6 | from django.test import TestCase |
… |
… |
class GetOrCreateTests(TestCase):
|
50 | 52 | ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different" |
51 | 53 | ) |
52 | 54 | self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original") |
| 55 | |
| 56 | # get_or_crete should raise IntegrityError's with the full traceback. |
| 57 | # This is tested by checking that a know method call is in the traceback. |
| 58 | try: |
| 59 | ManualPrimaryKeyTest.objects.get_or_create(id=1, data="Different") |
| 60 | except IntegrityError, e: |
| 61 | formatted_traceback = traceback.format_exc() |
| 62 | contains_insert_query = 'obj.save' in formatted_traceback |
| 63 | self.assertTrue(contains_insert_query, |
| 64 | "The traceback didn't contain 'obj.save'.") |
| 65 | No newline at end of file |