]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- remove the ``__iter__()`` with notimplemented since it interferes
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jun 2013 20:32:12 +0000 (16:32 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jun 2013 20:42:46 +0000 (16:42 -0400)
with legitimate iterable detection, [ticket:2726]

Conflicts:
doc/build/changelog/changelog_09.rst

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

index 211668867e9ce4ed35f3984eaaba6505ad053b05..7e8e618a4e83a39994f7aacdff742c8ed8173d67 100644 (file)
@@ -6,6 +6,21 @@
 .. changelog::
     :version: 0.8.2
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 2726
+
+        Removed the "not implemented" ``__iter__()`` call from the base
+        :class:`.ColumnOperators` class, while this was introduced
+        in 0.8.0 to prevent an endless, memory-growing loop when one also
+        implements a ``__getitem__()`` method on a custom
+        operator and then calls erroneously ``list()`` on that object,
+        it had the effect of causing column elements to report that they
+        were in fact iterable types which then throw an error when you try
+        to iterate.   There's no real way to have both sides here so we
+        stick with Python best practices.  Careful with implementing
+        ``__getitem__()`` on your custom operators!
+
     .. change::
       :tags: feature, orm
       :tickets: 2736
index a7e6af11611173801d5b2ec122bb7da471c496ac..6f3705661a1e04e9424c3c609d575ea24d57938f 100644 (file)
@@ -310,11 +310,6 @@ class ColumnOperators(Operators):
         """
         return self.operate(neg)
 
-    def __iter__(self):
-        """Block calls to list() from calling __getitem__() endlessly."""
-
-        raise NotImplementedError("Class %s is not iterable" % self.__class__)
-
     def __getitem__(self, index):
         """Implement the [] operator.
 
index d1db733e09302d99a9ce29f230bb0718ac651ef2..b3919d0dab089fff7e85b7422b55722f2910be0c 100644 (file)
@@ -15,7 +15,7 @@ from sqlalchemy.dialects import mysql, firebird, postgresql, oracle, \
         sqlite, mssql
 from sqlalchemy import util
 import datetime
-
+import collections
 from sqlalchemy import text, literal_column
 
 class LoopOperate(operators.ColumnOperators):
@@ -352,17 +352,16 @@ class ExtensionOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):
             "x -> :x_1"
         )
 
-    def test_no_endless_list_call(self):
+    @testing.requires.python26
+    def test_op_not_an_iterator(self):
+        # see [ticket:2726]
         class MyType(UserDefinedType):
             class comparator_factory(UserDefinedType.Comparator):
                 def __getitem__(self, index):
                     return self.op("->")(index)
 
-        assert_raises_message(
-            NotImplementedError,
-            "Class <class 'sqlalchemy.schema.Column'> is not iterable",
-            list, Column('x', MyType())
-        )
+        col = Column('x', MyType())
+        assert not isinstance(col, collections.Iterable)
 
     def test_lshift(self):
         class MyType(UserDefinedType):