From: Mike Bayer Date: Wed, 17 Feb 2016 20:21:00 +0000 (-0500) Subject: - do the trailing comma logic of tuple repr() exactly X-Git-Tag: rel_1_1_0b1~98^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf1d03a9e58a0256db0b1f7389e23a6d11c4a964;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - do the trailing comma logic of tuple repr() exactly --- diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 98d9cc9447..d40bf48f1f 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -311,8 +311,9 @@ class _repr_row(_repr_base): def __repr__(self): trunc = self.trunc - return "(%s)" % ( - "".join(trunc(value) + "," for value in self.row) + return "(%s%s)" % ( + ", ".join(trunc(value) for value in self.row), + "," if len(self.row) == 1 else "" ) @@ -391,8 +392,10 @@ class _repr_params(_repr_base): ) ) elif typ is self._TUPLE: - return "(%s)" % ( - "".join(trunc(value) + "," for value in params) + return "(%s%s)" % ( + ", ".join(trunc(value) for value in params), + "," if len(params) == 1 else "" + ) else: return "[%s]" % ( diff --git a/test/engine/test_logging.py b/test/engine/test_logging.py index 847ba06c4e..efdee8aef6 100644 --- a/test/engine/test_logging.py +++ b/test/engine/test_logging.py @@ -69,6 +69,24 @@ class LogParamsTest(fixtures.TestBase): ) ) + def test_log_large_multi_parameter(self): + import random + lp1 = ''.join(chr(random.randint(52, 85)) for i in range(5)) + lp2 = ''.join(chr(random.randint(52, 85)) for i in range(8)) + lp3 = ''.join(chr(random.randint(52, 85)) for i in range(670)) + + self.eng.execute( + "SELECT ?, ?, ?", + (lp1, lp2, lp3) + ) + + eq_( + self.buf.buffer[1].message, + "('%s', '%s', '%s ... (372 characters truncated) ... %s')" % ( + lp1, lp2, lp3[0:149], lp3[-149:] + ) + ) + def test_log_large_parameter_multiple(self): import random lp1 = ''.join(chr(random.randint(52, 85)) for i in range(5000))