summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/compat.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-18 11:00:12 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-18 11:00:12 -0400
commit0bb05ffdf066ba108883a0a4165cb11894fb3d88 (patch)
treed43edaf796cfb5a4853e8832db6f0e429deb9c5d /lib/sqlalchemy/util/compat.py
parente5d0592180a554a1220985d28dab8533030281f0 (diff)
downloadsqlalchemy-0bb05ffdf066ba108883a0a4165cb11894fb3d88.tar.gz
Reworked internal exception raises that emit
a rollback() before re-raising, so that the stack trace is preserved from sys.exc_info() before entering the rollback. This so that the traceback is preserved when using coroutine frameworks which may have switched contexts before the rollback function returns. [ticket:2703]
Diffstat (limited to 'lib/sqlalchemy/util/compat.py')
-rw-r--r--lib/sqlalchemy/util/compat.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py
index 2a0f06f8e..0f0a2f674 100644
--- a/lib/sqlalchemy/util/compat.py
+++ b/lib/sqlalchemy/util/compat.py
@@ -140,3 +140,29 @@ else:
def b(s):
return s
+
+if py3k:
+ def reraise(tp, value, tb=None, cause=None):
+ if cause is not None:
+ value.__cause__ = cause
+ if value.__traceback__ is not tb:
+ raise value.with_traceback(tb)
+ raise value
+
+ def raise_from_cause(exception, exc_info):
+ exc_type, exc_value, exc_tb = exc_info
+ reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
+else:
+ exec("""def reraise(tp, value, tb=None, cause=None):
+ raise tp, value, tb
+ """)
+
+ def raise_from_cause(exception, exc_info):
+ # not as nice as that of Py3K, but at least preserves
+ # the code line where the issue occurred
+ exc_type, exc_value, exc_tb = exc_info
+ reraise(type(exception), exception, tb=exc_tb)
+
+
+
+