equal and not-equal operators should not be associative

Issue #3799 resolved
John Passaro created an issue

Example

from sqlalchemy import literal
eq_stmt = (literal(1) == 1) == (literal(1) == 0)
ne_stmt = (literal(1) != 1) != (literal(1) != 0)
print eq_stmt; print ne_stmt

output:

:param_1 = :param_2 = :param_3 = :param_4
:param_1 != :param_2 != :param_3 != :param_4

Expect:

(:param_1 = :param_2) = (:param_3 = :param_4)
(:param_1 != :param_2) != (:param_3 != :param_4)

See PR (including test case) at https://gerrit.sqlalchemy.org/#/c/190/, and discussion on original PR at https://github.com/zzzeek/sqlalchemy/pull/308.

Not high priority as far as the reporter is concerned, it is easy to work around.

Comments (2)

  1. Mike Bayer repo owner

    Exclude eq and ne from associative operators

    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

    → <<cset 2c4119d1eb9e>>

  2. Log in to comment