.. changelog::
:version: 0.8.5
+ .. change::
+ :tags: bug, sql
+ :tickets: 2957
+ :versions: 0.9.3
+
+ Fixed bug where :meth:`.in_()` would go into an endless loop if
+ erroneously passed a column expression whose comparator included
+ the ``__getitem__()`` method, such as a column that uses the
+ :class:`.postgresql.ARRAY` type.
+
.. change::
:tags: bug, orm
:tickets: 2951
elif isinstance(seq_or_selectable, (Selectable, TextClause)):
return self._boolean_compare(expr, op, seq_or_selectable,
negate=negate_op, **kw)
+ elif isinstance(seq_or_selectable, ClauseElement):
+ raise exc.InvalidRequestError('in_() accepts'
+ ' either a list of expressions '
+ 'or a selectable: %r' % seq_or_selectable)
# Handle non selectable arguments as sequences
args = []
for o in seq_or_selectable:
if not _is_literal(o):
if not isinstance(o, ColumnOperators):
- raise exc.InvalidRequestError('in() function accept'
- 's either a list of non-selectable values, '
+ raise exc.InvalidRequestError('in_() accepts'
+ ' either a list of expressions '
'or a selectable: %r' % o)
elif o is None:
o = null()
)
self._loop_test(operators.notin_op, [1, 2, 3])
+ def test_in_no_accept_list_of_non_column_element(self):
+ left = column('left')
+ foo = ClauseList()
+ assert_raises_message(
+ exc.InvalidRequestError,
+ r"in_\(\) accepts either a list of expressions or a selectable:",
+ left.in_, [foo]
+ )
+
+ def test_in_no_accept_non_list_non_selectable(self):
+ left = column('left')
+ right = column('right')
+ assert_raises_message(
+ exc.InvalidRequestError,
+ r"in_\(\) accepts either a list of expressions or a selectable:",
+ left.in_, right
+ )
+
+ def test_in_no_accept_non_list_thing_with_getitem(self):
+ # test [ticket:2726]
+ class HasGetitem(String):
+ class comparator_factory(String.Comparator):
+ def __getitem__(self, value):
+ return value
+
+ left = column('left')
+ right = column('right', HasGetitem)
+ assert_raises_message(
+ exc.InvalidRequestError,
+ r"in_\(\) accepts either a list of expressions or a selectable:",
+ left.in_, right
+ )
+
def test_collate(self):
left = column('left')
right = "some collation"