]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Preserve type for math negation
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Jul 2016 16:44:47 +0000 (12:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Jul 2016 16:45:51 +0000 (12:45 -0400)
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)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/sql/default_comparator.py
test/sql/test_operators.py

index defee6d06e0cbc23cd2d2abdca7ac02111be1ae5..8a6b6b370326552065e1571aac7496160e682ec3 100644 (file)
 .. 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
index d180dbc02eee8ff206a4d047983e3e16ce96afb7..51a05387e9743e62adfade5d92e80dfa2b9d6655 100644 (file)
@@ -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):
index 1a0554e5071324be705ea702236d8664473c4859..8196b589401a8beded83eaf1f0588a18eee477c0 100644 (file)
@@ -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'