diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2016-09-20 11:55:19 -0400 |
---|---|---|
committer | Gerrit Code Review <gerrit2@ln3.zzzcomputing.com> | 2016-09-20 11:55:19 -0400 |
commit | b9a7a74d5e729408fcac86fe2919aa423c59d863 (patch) | |
tree | 78b7d2eba89f93faeaf9ea083863e39644188545 | |
parent | dea7c2bd8e7e852b6a41d6e0ec3af35f33917a70 (diff) | |
parent | 2c4119d1eb9e231676bf4facedf46849970b8253 (diff) | |
download | sqlalchemy-b9a7a74d5e729408fcac86fe2919aa423c59d863.tar.gz |
Merge "Exclude eq and ne from associative operators"
-rw-r--r-- | doc/build/changelog/changelog_11.rst | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/operators.py | 2 | ||||
-rw-r--r-- | test/sql/test_operators.py | 8 |
3 files changed, 19 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 3919c6ec6..0d6c6b159 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -22,6 +22,16 @@ :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: 3767 diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index bf470710d..142606680 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -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]) diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index b6e80de4b..99f8a10ca 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -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' |