Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1241 from jaylett/master

Explicit exception chaining for db exceptions by setting __cause__ in py2
  • Loading branch information...
commit 687afdaa48681e5c094679e7295d09b36a41b657 2 parents 4f4e924 + 5448555
Marc Tamlyn authored June 04, 2013
3  django/db/utils.py
@@ -91,8 +91,7 @@ def __exit__(self, exc_type, exc_value, traceback):
91 91
                 except AttributeError:
92 92
                     args = (exc_value,)
93 93
                 dj_exc_value = dj_exc_type(*args)
94  
-                if six.PY3:
95  
-                    dj_exc_value.__cause__ = exc_value
  94
+                dj_exc_value.__cause__ = exc_value
96 95
                 # Only set the 'errors_occurred' flag for errors that may make
97 96
                 # the connection unusable.
98 97
                 if dj_exc_type not in (DataError, IntegrityError):
8  docs/ref/exceptions.txt
@@ -152,10 +152,16 @@ The Django wrappers for database exceptions behave exactly the same as
152 152
 the underlying database exceptions. See :pep:`249`, the Python Database API
153 153
 Specification v2.0, for further information.
154 154
 
  155
+As per :pep:`3134`, a ``__cause__`` attribute is set with the original
  156
+(underlying) database exception, allowing access to any additional
  157
+information provided. (Note that this attribute is available under
  158
+both Python 2 and Python 3, although :pep:`3134` normally only applies
  159
+to Python 3.)
  160
+
155 161
 .. versionchanged:: 1.6
156 162
 
157 163
     Previous version of Django only wrapped ``DatabaseError`` and
158  
-    ``IntegrityError``.
  164
+    ``IntegrityError``, and did not provide ``__cause__``.
159 165
 
160 166
 .. exception:: models.ProtectedError
161 167
 

0 notes on commit 687afda

Please sign in to comment.
Something went wrong with that request. Please try again.