[Sqlalchemy-tickets] Issue #3300: create_lazy_clause() is only turning a target col into a bind on
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-02-02 16:53:43
|
New issue 3300: create_lazy_clause() is only turning a target col into a bind on the first occurrence https://bitbucket.org/zzzeek/sqlalchemy/issue/3300/create_lazy_clause-is-only-turning-a Mike Bayer: the logic commented out below has the effect that if a "local" column appears more than once in the clause, it only gets turned to a bound param once. need to determine the rationale for this logic and get it to be more specific to the case where it is needed. ``` #!diff diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index df2250a..9a5e1ba 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -2709,10 +2709,10 @@ class JoinCondition(object): def col_to_bind(col): if (reverse_direction and col in lookup) or \ (not reverse_direction and "local" in col._annotations): - if col in lookup: - for tobind, equated in lookup[col]: - if equated in binds: - return None + #if col in lookup: + # for tobind, equated in lookup[col]: + # if equated in binds: + # return None if col not in binds: binds[col] = sql.bindparam( None, None, type_=col.type, unique=True) ``` this script illustrates three different join conditions, the third one is pretty simple, which all illustrate the same thing happening: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() # NOT (:param_1 != a.attr OR a.attr IS NULL OR a.attr IS NULL) # OR a.attr IS NULL AND a.attr IS NULL notdistinct_1 = lambda a, b: ~( (a != b) | (a == None) | (b == None)) | ((a == None) & (b == None)) # :param_1 != a.attr OR a.attr IS NULL OR a.attr IS NULL notdistinct_2 = lambda a, b: ( (a != b) | (a == None) | (b == None)) # :param_1 = a.attr OR a.attr = a.attr notdistinct_3 = lambda a, b: ((a == b) | (b == a)) class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) attr = Column(Integer) collection = relationship( "A", viewonly=True, primaryjoin=lambda: and_( notdistinct_3(A.attr, foreign(remote(A.attr))) ) ) configure_mappers() print A.collection.property.strategy._lazywhere ``` Responsible: zzzeek |