From: Mike Bayer Date: Mon, 3 Jun 2013 20:32:12 +0000 (-0400) Subject: - remove the ``__iter__()`` with notimplemented since it interferes X-Git-Tag: rel_0_8_2~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33d3e11cbf596c64abc3ced1d5aa01989afe0ad8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - remove the ``__iter__()`` with notimplemented since it interferes with legitimate iterable detection, [ticket:2726] Conflicts: doc/build/changelog/changelog_09.rst --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 211668867e..7e8e618a4e 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -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 diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index a7e6af1161..6f3705661a 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -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. diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index d1db733e09..b3919d0dab 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -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 is not iterable", - list, Column('x', MyType()) - ) + col = Column('x', MyType()) + assert not isinstance(col, collections.Iterable) def test_lshift(self): class MyType(UserDefinedType):