diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-12-11 14:30:18 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-12-11 14:30:18 -0500 |
commit | 9087157749a0527d6af37e58166793fc7e2f0bf7 (patch) | |
tree | 9e8c201bb5c01c84d14dd6ce2038955cd8d548d6 /lib/sqlalchemy/exc.py | |
parent | 164bff07496c345c3c57a8b26439aa6a0fbce3b8 (diff) | |
download | sqlalchemy-9087157749a0527d6af37e58166793fc7e2f0bf7.tar.gz |
- The :class:`.exc.StatementError` or DBAPI-related subclass
now can accomodate additional information about the "reason" for
the exception; the :class:`.Session` now adds some detail to it
when the exception occurs within an autoflush. This approach
is taken as opposed to combining :class:`.FlushError` with
a Python 3 style "chained exception" approach so as to maintain
compatibility both with Py2K code as well as code that already
catches ``IntegrityError`` or similar.
Diffstat (limited to 'lib/sqlalchemy/exc.py')
-rw-r--r-- | lib/sqlalchemy/exc.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 3c0c6c365..93722fe99 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -219,6 +219,10 @@ class StatementError(SQLAlchemyError): self.statement = statement self.params = params self.orig = orig + self.detail = [] + + def add_detail(self, msg): + self.detail.append(msg) def __reduce__(self): return self.__class__, (self.args[0], self.statement, @@ -227,8 +231,13 @@ class StatementError(SQLAlchemyError): def __str__(self): from sqlalchemy.sql import util params_repr = util._repr_params(self.params, 10) - return ' '.join((SQLAlchemyError.__str__(self), - repr(self.statement), repr(params_repr))) + + return ' '.join([ + "(%s)" % det for det in self.detail + ] + [ + SQLAlchemyError.__str__(self), + repr(self.statement), repr(params_repr) + ]) def __unicode__(self): return self.__str__() |