diff options
| author | Raphaƫl Hertzog <hertzog@debian.org> | 2015-11-25 12:54:52 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-03 16:31:50 -0500 |
| commit | 9f4e031bd3cb13d5879fe9ad3d889ce861b0babe (patch) | |
| tree | 79be55cfa7c8e9fe004e29b2e12c2fb60283e322 /django/db/utils.py | |
| parent | c6ea4ed5d23671deee6e736fe1daba2c650a4fbb (diff) | |
Fixed #25761 -- Added __cause__.__traceback__ to reraised exceptions.
When Django reraises an exception, it sets the __cause__ attribute even
in Python 2, mimicking Python's 3 behavior for "raise Foo from Bar".
However, Python 3 also ensures that all exceptions have a __traceback__
attribute and thus the "traceback2" Python 2 module (backport of Python
3's "traceback" module) relies on the fact that whenever you have a
__cause__ attribute, the recorded exception also has a __traceback__
attribute.
This is breaking testtools which is using traceback2 (see
https://github.com/testing-cabal/testtools/issues/162).
This commit fixes this inconsistency by ensuring that Django sets
the __traceback__ attribute on any exception stored in a __cause__
attribute of a reraised exception.
Diffstat (limited to 'django/db/utils.py')
| -rw-r--r-- | django/db/utils.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/django/db/utils.py b/django/db/utils.py index aaa992c040..92354b7bad 100644 --- a/django/db/utils.py +++ b/django/db/utils.py @@ -85,6 +85,8 @@ class DatabaseErrorWrapper(object): if issubclass(exc_type, db_exc_type): dj_exc_value = dj_exc_type(*exc_value.args) dj_exc_value.__cause__ = exc_value + if not hasattr(exc_value, '__traceback__'): + exc_value.__traceback__ = traceback # Only set the 'errors_occurred' flag for errors that may make # the connection unusable. if dj_exc_type not in (DataError, IntegrityError): |
