summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2013-06-04 05:28:21 -0700
committerMarc Tamlyn <marc.tamlyn@gmail.com>2013-06-04 05:28:21 -0700
commit687afdaa48681e5c094679e7295d09b36a41b657 (patch)
treec7bf9489c027a33de70dbc9ed1a7744e733b70c0
parent4f4e9243e4cf585e32a882804084853108ef94c0 (diff)
parent54485557855d58d9a5027511025d5ab22f721c6d (diff)
Merge pull request #1241 from jaylett/master
Explicit exception chaining for db exceptions by setting __cause__ in py2
-rw-r--r--django/db/utils.py3
-rw-r--r--docs/ref/exceptions.txt8
2 files changed, 8 insertions, 3 deletions
diff --git a/django/db/utils.py b/django/db/utils.py
index 99804ee8fa..bd7e10d24c 100644
--- a/django/db/utils.py
+++ b/django/db/utils.py
@@ -91,8 +91,7 @@ class DatabaseErrorWrapper(object):
except AttributeError:
args = (exc_value,)
dj_exc_value = dj_exc_type(*args)
- if six.PY3:
- dj_exc_value.__cause__ = exc_value
+ dj_exc_value.__cause__ = exc_value
# Only set the 'errors_occurred' flag for errors that may make
# the connection unusable.
if dj_exc_type not in (DataError, IntegrityError):
diff --git a/docs/ref/exceptions.txt b/docs/ref/exceptions.txt
index 6a5e6f49d5..b15bbea8fa 100644
--- a/docs/ref/exceptions.txt
+++ b/docs/ref/exceptions.txt
@@ -152,10 +152,16 @@ The Django wrappers for database exceptions behave exactly the same as
the underlying database exceptions. See :pep:`249`, the Python Database API
Specification v2.0, for further information.
+As per :pep:`3134`, a ``__cause__`` attribute is set with the original
+(underlying) database exception, allowing access to any additional
+information provided. (Note that this attribute is available under
+both Python 2 and Python 3, although :pep:`3134` normally only applies
+to Python 3.)
+
.. versionchanged:: 1.6
Previous version of Django only wrapped ``DatabaseError`` and
- ``IntegrityError``.
+ ``IntegrityError``, and did not provide ``__cause__``.
.. exception:: models.ProtectedError