[Sqlalchemy-tickets] Issue #3308: Cannot use hybrid_property in filter_by (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: thiefmaster <iss...@bi...> - 2015-02-18 13:06:37
|
New issue 3308: Cannot use hybrid_property in filter_by https://bitbucket.org/zzzeek/sqlalchemy/issue/3308/cannot-use-hybrid_property-in-filter_by thiefmaster: ```python from sqlalchemy import * from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Test(Base): __tablename__ = 'test' id = Column(Integer, primary_key=True) foo = Column(Integer) @hybrid_property def foo_123(self): return self.foo == 123 e = create_engine('postgresql:///test', echo=True) Base.metadata.create_all(e) s = Session(e) s.query(Test).filter_by(foo_123=True).all() ``` The WHERE clause generated from this is `test.foo = 123 = true` which fails. I think it should be `WHERE (test.foo = 123) = true ` instead. Maybe a hybrid property could automatically insert parentheses around the generated criterion? That shouldn't break anything but avoid this bug. |