diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-05-22 10:56:06 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-05-22 10:56:06 +0200 |
| commit | 0e51d8eb66121b2558a38c9f4e366df781046873 (patch) | |
| tree | 219f60c5070122e94e4a419f6e7442c8c8312d3c /django | |
| parent | adeec00979d1b365535b8f26fda4a5f7173e975d (diff) | |
Fixed #20463 -- Made get_or_create more robust.
When an exception other than IntegrityError was raised, get_or_create
could fail and leave the database connection in an unusable state.
Thanks UloPe for the report.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index cc07ecbfd0..b2ffa32004 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -9,7 +9,7 @@ import warnings from django.conf import settings from django.core import exceptions -from django.db import connections, router, transaction, IntegrityError +from django.db import connections, router, transaction, DatabaseError from django.db.models.constants import LOOKUP_SEP from django.db.models.fields import AutoField from django.db.models.query_utils import (Q, select_related_descend, @@ -382,13 +382,13 @@ class QuerySet(object): obj.save(force_insert=True, using=self.db) transaction.savepoint_commit(sid, using=self.db) return obj, True - except IntegrityError: + except DatabaseError: transaction.savepoint_rollback(sid, using=self.db) exc_info = sys.exc_info() try: return self.get(**lookup), False except self.model.DoesNotExist: - # Re-raise the IntegrityError with its original traceback. + # Re-raise the DatabaseError with its original traceback. six.reraise(*exc_info) def _earliest_or_latest(self, field_name=None, direction="-"): |
