]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Exclude eq and ne from associative operators
authorJohn Passaro <john.a.passaro@gmail.com>
Mon, 19 Sep 2016 19:43:46 +0000 (15:43 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 Sep 2016 21:17:07 +0000 (17:17 -0400)
The "eq" and "ne" operators are no longer part of the list of
"associative" operators, while they remain considered to be
"commutative".  This allows an expression like ``(x == y) == z``
to be maintained at the SQL level with parenthesis.  Pull request
courtesy John Passaro.

Fixes: #3799
Change-Id: I3759d8987b35649d7418b6524316c9e70c857e68
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/308

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/sql/operators.py
test/sql/test_operators.py

index a0970348911e60d784006429616a64802bfcb2f5..4693eda29b4a6256a5d05d1196b2edb34ac346d9 100644 (file)
 .. changelog::
     :version: 1.1.0
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 3799
+
+        The "eq" and "ne" operators are no longer part of the list of
+        "associative" operators, while they remain considered to be
+        "commutative".  This allows an expression like ``(x == y) == z``
+        to be maintained at the SQL level with parenthesis.  Pull request
+        courtesy John Passaro.
+
     .. change::
         :tags: bug, orm
         :tickets: 3788
index bf470710db7bce229b71d2869e63a41236558d28..14260668045c1f46074ed38d16c321cd07225b1c 100644 (file)
@@ -917,7 +917,7 @@ def mirror(op):
     return _mirror.get(op, op)
 
 
-_associative = _commutative.union([concat_op, and_, or_])
+_associative = _commutative.union([concat_op, and_, or_]).difference([eq, ne])
 
 _natural_self_precedent = _associative.union([
     getitem, json_getitem_op, json_path_getitem_op])
index b6e80de4bad82d8f72c80d8c1f71e299abb09615..99f8a10ca3c605a119284174edea830fe63dc450 100644 (file)
@@ -1538,6 +1538,14 @@ class OperatorAssociativityTest(fixtures.TestBase, testing.AssertsCompiledSQL):
         f = column('f')
         self.assert_compile(f / (f / (f - f)), "f / (f / (f - f))")
 
+    def test_associativity_22(self):
+        f = column('f')
+        self.assert_compile((f==f) == f, '(f = f) = f')
+
+    def test_associativity_23(self):
+        f = column('f')
+        self.assert_compile((f!=f) != f, '(f != f) != f')
+
 
 class IsDistinctFromTest(fixtures.TestBase, testing.AssertsCompiledSQL):
     __dialect__ = 'default'