diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-02 10:15:40 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-02 10:20:54 -0500 |
| commit | e0a580b3d055a600afae61840058a5a30ef5fe74 (patch) | |
| tree | 592356800f2b452028bae1f91ffcffad8157aa87 /test/sql | |
| parent | c8b3d4ed3f2638599fc73486cf0f724fa033a638 (diff) | |
| download | sqlalchemy-e0a580b3d055a600afae61840058a5a30ef5fe74.tar.gz | |
- Fixed issue where inadvertent use of the Python ``__contains__``
override with a column expression (e.g. by using ``'x' in col``)
would cause an endless loop in the case of an ARRAY type, as Python
defers this to ``__getitem__`` access which never raises for this
type. Overall, all use of ``__contains__`` now raises
NotImplementedError.
fixes #3642
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_operators.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 6a6c749a4..86286a9a3 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -15,7 +15,8 @@ from sqlalchemy.sql.elements import _literal_as_text from sqlalchemy.schema import Column, Table, MetaData from sqlalchemy.sql import compiler from sqlalchemy.types import TypeEngine, TypeDecorator, UserDefinedType, \ - Boolean, NullType, MatchType, Indexable, Concatenable, ARRAY, JSON + Boolean, NullType, MatchType, Indexable, Concatenable, ARRAY, JSON, \ + DateTime from sqlalchemy.dialects import mysql, firebird, postgresql, oracle, \ sqlite, mssql from sqlalchemy import util @@ -265,6 +266,18 @@ class DefaultColumnComparatorTest(fixtures.TestBase): expr.operator, operator.add ) + def test_contains_override_raises(self): + for col in [ + Column('x', String), + Column('x', Integer), + Column('x', DateTime) + ]: + assert_raises_message( + NotImplementedError, + "Operator 'contains' is not supported on this expression", + lambda: 'foo' in col + ) + class CustomUnaryOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL): __dialect__ = 'default' @@ -820,6 +833,15 @@ class ArrayIndexOpTest(fixtures.TestBase, testing.AssertsCompiledSQL): checkparams={'x_1': 5} ) + def test_contains_override_raises(self): + col = Column('x', self.MyType()) + + assert_raises_message( + NotImplementedError, + "Operator 'contains' is not supported on this expression", + lambda: 'foo' in col + ) + def test_getindex_sqlexpr(self): col = Column('x', self.MyType()) |
