]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where :meth:`.in_()` would go into an endless loop if
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 13 Feb 2014 20:19:12 +0000 (15:19 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 13 Feb 2014 20:21:28 +0000 (15:21 -0500)
erroneously passed a column expression whose comparator included
the ``__getitem__()`` method, such as a column that uses the
:class:`.postgresql.ARRAY` type. [ticket:2957]

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/expression.py
test/sql/test_operators.py

index 83c660e79c7b2adc0bdd22261051cc0b62dad05d..71aee218b397175ea29d4e58271b01bccb71eaaf 100644 (file)
 .. 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
index 49b33bda680c759bd4285db5c73d3bf3679cd521..287707c327b5099aac9593a908c89fe803486858 100644 (file)
@@ -2618,14 +2618,18 @@ class _DefaultColumnComparator(operators.ColumnOperators):
         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()
index ce91c5b5e35759777fc8dae874e36f6102647768..1108c5daae3f95e88a12af142e5071eacb117ac1 100644 (file)
@@ -149,6 +149,39 @@ class DefaultColumnComparatorTest(fixtures.TestBase):
             )
         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"