From: Mike Bayer Date: Fri, 1 Jul 2016 16:44:47 +0000 (-0400) Subject: Preserve type for math negation X-Git-Tag: rel_1_0_14~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9880da342f28960df480ddabc811e623a0b87a12;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Preserve type for math negation Fixed issue in SQL math negation operator where the type of the expression would no longer be the numeric type of the original. This would cause issues where the type determined result set behaviors. Change-Id: If0e339614a3686e251235fc94b6f59310c4630a5 Fixes: #3735 (cherry picked from commit 5c60aaefd32a7bdee611fb340911409e0b8223ed) --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index defee6d06e..8a6b6b3703 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,15 @@ .. changelog:: :version: 1.0.14 + .. change:: + :tags: bug, sql + :tickets: 3735 + + Fixed issue in SQL math negation operator where the type of the + expression would no longer be the numeric type of the original. + This would cause issues where the type determined result set + behaviors. + .. change:: :tags: bug, sql :tickets: 3728 diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py index d180dbc02e..51a05387e9 100644 --- a/lib/sqlalchemy/sql/default_comparator.py +++ b/lib/sqlalchemy/sql/default_comparator.py @@ -176,7 +176,7 @@ def _inv_impl(expr, op, **kw): def _neg_impl(expr, op, **kw): """See :meth:`.ColumnOperators.__neg__`.""" - return UnaryExpression(expr, operator=operators.neg) + return UnaryExpression(expr, operator=operators.neg, type_=expr.type) def _match_impl(expr, op, other, **kw): diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 1a0554e507..8196b58940 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -1573,6 +1573,12 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL): "SELECT mytable.myid, mytable.name FROM " "mytable WHERE mytable.myid != :myid_1 AND NOT mytable.name") + def test_negate_operator_type(self): + is_( + (-self.table1.c.myid).type, + self.table1.c.myid.type, + ) + class LikeTest(fixtures.TestBase, testing.AssertsCompiledSQL): __dialect__ = 'default'