[Sqlalchemy-tickets] Issue #3642: Endless loop with `foo in arraycolumn` (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: thiefmaster <iss...@bi...> - 2016-02-02 09:53:17
|
New issue 3642: Endless loop with `foo in arraycolumn` https://bitbucket.org/zzzeek/sqlalchemy/issues/3642/endless-loop-with-foo-in-arraycolumn thiefmaster: This example never terminates: ```python from sqlalchemy import * from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import * Base = declarative_base() class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) chain = Column(ARRAY(Integer)) e = create_engine('postgresql:///test', echo=True) Base.metadata.create_all(e) s = Session(e) print s.query(Foo).filter(123 in Foo.chain).all() ``` Traceback on ^C: ```pytb ^CTraceback (most recent call last): File "satest.py", line 22, in <module> print s.query(Foo).filter(123 in Foo.chain).all() File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/sqlalchemy/sql/operators.py", line 301, in __eq__ return self.operate(eq, other) File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 739, in operate return op(self.comparator, *other, **kwargs) File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/sqlalchemy/sql/operators.py", line 301, in __eq__ return self.operate(eq, other) File "<string>", line 1, in <lambda> File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/sqlalchemy/sql/type_api.py", line 60, in operate return o[0](self.expr, op, *(other + o[1:]), **kwargs) File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.py", line 69, in _boolean_compare negate=negate, modifiers=kwargs) File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 2734, in __init__ self.type = type_api.to_instance(type_) KeyboardInterrupt ``` >From looking at the code `__contains__` is not supported, but it should result in an exception and not in a hang. --- Also, I think it would be useful to implement `__contains__` to call `self.contains([value])`. Using `.any(123)` is not an option since it does not make use of a GIN index on the table, while `.contains([123])` does even though both do the same thing. |