From 9f4e031bd3cb13d5879fe9ad3d889ce861b0babe Mon Sep 17 00:00:00 2001 From: Raphaƫl Hertzog Date: Wed, 25 Nov 2015 12:54:52 +0100 Subject: 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. --- django/utils/timezone.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'django/utils') diff --git a/django/utils/timezone.py b/django/utils/timezone.py index 70fd5e3e48..205cac44a9 100644 --- a/django/utils/timezone.py +++ b/django/utils/timezone.py @@ -146,6 +146,8 @@ class LocalTimezone(ReferenceLocalTimezone): exc_value = exc_type( "Unsupported value: %r. You should install pytz." % dt) exc_value.__cause__ = exc + if not hasattr(exc, '__traceback__'): + exc.__traceback__ = sys.exc_info()[2] six.reraise(exc_type, exc_value, sys.exc_info()[2]) utc = pytz.utc if pytz else UTC() -- cgit v1.3