Skip to content

Endless loop with foo in arraycolumn #3642

@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Adrian (@thiefmaster)

This example never terminates:

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:

^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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions