def __str__(self):
from sqlalchemy.sql import util
- params_repr = util._repr_params(self.params, 10)
+ details = [SQLAlchemyError.__str__(self)]
+ if self.statement:
+ details.append("[SQL: %r]" % self.statement)
+ if self.params:
+ params_repr = util._repr_params(self.params, 10)
+ details.append("[parameters: %r]" % params_repr)
return ' '.join([
"(%s)" % det for det in self.detail
- ] + [
- SQLAlchemyError.__str__(self),
- repr(self.statement), repr(params_repr)
- ])
+ ] + details)
def __unicode__(self):
return self.__str__()
# not a DBAPI error, statement is present.
# raise a StatementError
if not isinstance(orig, dbapi_base_err) and statement:
- msg = traceback.format_exception_only(
- orig.__class__, orig)[-1].strip()
return StatementError(
- "%s (original cause: %s)" % (str(orig), msg),
+ "(%s.%s) %s" %
+ (orig.__class__.__module__, orig.__class__.__name__,
+ orig),
statement, params, orig
)
text = 'Error in str() of DB-API-generated exception: ' + str(e)
StatementError.__init__(
self,
- '(%s) %s' % (orig.__class__.__name__, text),
+ '(%s.%s) %s' % (
+ orig.__class__.__module__, orig.__class__.__name__, text, ),
statement,
params,
orig
'this is a message',
None, OperationalError(), DatabaseError)
except sa_exceptions.DBAPIError as exc:
- assert str(exc) \
- == "(OperationalError) 'this is a message' None"
+ eq_(
+ str(exc),
+ "(test.base.test_except.OperationalError) "
+ "[SQL: 'this is a message']")
def test_tostring_large_dict(self):
try:
OperationalError(), DatabaseError)
except sa_exceptions.DBAPIError as exc:
assert str(exc).startswith(
- "(OperationalError) 'this is a message' {")
+ "(test.base.test_except.OperationalError) "
+ "[SQL: 'this is a message'] [parameters: {")
def test_tostring_large_list(self):
try:
OperationalError(), DatabaseError)
except sa_exceptions.DBAPIError as exc:
assert str(exc).startswith(
- "(OperationalError) 'this is a "
- "message' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]")
+ "(test.base.test_except.OperationalError) "
+ "[SQL: 'this is a message'] [parameters: "
+ "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]")
def test_tostring_large_executemany(self):
try:
except sa_exceptions.DBAPIError as exc:
eq_(
str(exc),
- "(OperationalError) 'this is a message' [{1: 1}, "
+ "(test.base.test_except.OperationalError) "
+ "[SQL: 'this is a message'] [parameters: [{1: 1}, "
"{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: "
- "1}, {1: 1}, {1: 1}]"
+ "1}, {1: 1}, {1: 1}]]"
)
try:
raise sa_exceptions.DBAPIError.instance('this is a message', [
], OperationalError(), DatabaseError)
except sa_exceptions.DBAPIError as exc:
eq_(str(exc),
- "(OperationalError) 'this is a message' [{1: 1}, "
+ "(test.base.test_except.OperationalError) "
+ "[SQL: 'this is a message'] [parameters: [{1: 1}, "
"{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, "
"{1: 1}, {1: 1} ... displaying 10 of 11 total "
- "bound parameter sets ... {1: 1}, {1: 1}]"
+ "bound parameter sets ... {1: 1}, {1: 1}]]"
)
try:
raise sa_exceptions.DBAPIError.instance(
except sa_exceptions.DBAPIError as exc:
eq_(
str(exc),
- "(OperationalError) 'this is a message' [(1,), "
- "(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]")
+ "(test.base.test_except.OperationalError) "
+ "[SQL: 'this is a message'] [parameters: [(1,), "
+ "(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]]")
try:
raise sa_exceptions.DBAPIError.instance('this is a message', [
(1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ), (1, ),
], OperationalError(), DatabaseError)
except sa_exceptions.DBAPIError as exc:
eq_(str(exc),
- "(OperationalError) 'this is a message' [(1,), "
+ "(test.base.test_except.OperationalError) "
+ "[SQL: 'this is a message'] [parameters: [(1,), "
"(1,), (1,), (1,), (1,), (1,), (1,), (1,) "
"... displaying 10 of 11 total bound "
- "parameter sets ... (1,), (1,)]"
+ "parameter sets ... (1,), (1,)]]"
)
def test_db_error_busted_dbapi(self):
def test_error_large_dict(self):
assert_raises_message(
tsa.exc.DBAPIError,
- r".*'INSERT INTO nonexistent \(data\) values \(:data\)' "
+ r".*'INSERT INTO nonexistent \(data\) values \(:data\)'\] "
+ "\[parameters: "
"\[{'data': '0'}, {'data': '1'}, {'data': '2'}, "
"{'data': '3'}, {'data': '4'}, {'data': '5'}, "
"{'data': '6'}, {'data': '7'} ... displaying 10 of "
assert_raises_message(
tsa.exc.DBAPIError,
r".*INSERT INTO nonexistent \(data\) values "
- "\(\?\)' \[\('0',\), \('1',\), \('2',\), \('3',\), "
- "\('4',\), \('5',\), \('6',\), \('7',\) ... displaying "
+ "\(\?\)'\] \[parameters: \[\('0',\), \('1',\), \('2',\), \('3',\), "
+ "\('4',\), \('5',\), \('6',\), \('7',\) "
+ "... displaying "
"10 of 100 total bound parameter sets ... "
"\('98',\), \('99',\)\]",
lambda: self.eng.execute(