Kaydet (Commit) 687afdaa authored tarafından Marc Tamlyn's avatar Marc Tamlyn

Merge pull request #1241 from jaylett/master

Explicit exception chaining for db exceptions by setting __cause__ in py2
...@@ -91,7 +91,6 @@ class DatabaseErrorWrapper(object): ...@@ -91,7 +91,6 @@ class DatabaseErrorWrapper(object):
except AttributeError: except AttributeError:
args = (exc_value,) args = (exc_value,)
dj_exc_value = dj_exc_type(*args) 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 # Only set the 'errors_occurred' flag for errors that may make
# the connection unusable. # the connection unusable.
......
...@@ -152,10 +152,16 @@ The Django wrappers for database exceptions behave exactly the same as ...@@ -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 the underlying database exceptions. See :pep:`249`, the Python Database API
Specification v2.0, for further information. 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 .. versionchanged:: 1.6
Previous version of Django only wrapped ``DatabaseError`` and Previous version of Django only wrapped ``DatabaseError`` and
``IntegrityError``. ``IntegrityError``, and did not provide ``__cause__``.
.. exception:: models.ProtectedError .. exception:: models.ProtectedError
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment