From: Mike Bayer Date: Mon, 21 Oct 2013 19:06:41 +0000 (-0400) Subject: - Fixed bug where :func:`.type_coerce` would not interpret ORM X-Git-Tag: rel_0_8_3~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=622772b46999561ad2033c8d30ee9b1aff75951b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug where :func:`.type_coerce` would not interpret ORM elements with a ``__clause_element__()`` method properly. [ticket:2849] Conflicts: lib/sqlalchemy/sql/elements.py --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index a6352a767c..5aed2b7d84 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -10,6 +10,14 @@ .. changelog:: :version: 0.8.3 + .. change:: + :tags: bug, sql + :tickets: 2849 + :versions: 0.9.0 + + Fixed bug where :func:`.type_coerce` would not interpret ORM + elements with a ``__clause_element__()`` method properly. + .. change:: :tags: bug, sql :tickets: 2842 diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 837716a41c..aa655f34fe 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -913,8 +913,8 @@ def type_coerce(expr, type_): """ type_ = sqltypes.to_instance(type_) - if hasattr(expr, '__clause_expr__'): - return type_coerce(expr.__clause_expr__()) + if hasattr(expr, '__clause_element__'): + return type_coerce(expr.__clause_element__(), type_) elif isinstance(expr, BindParameter): bp = expr._clone() bp.type = type_ diff --git a/test/sql/test_types.py b/test/sql/test_types.py index b58175d605..2556e8adc2 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -460,6 +460,17 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL): 'd1BIND_OUT' ) + class MyFoob(object): + def __clause_element__(self): + return t.c.data + + eq_( + testing.db.execute( + select([t.c.data, type_coerce(MyFoob(), MyType)]) + ).fetchall(), + [('d1', 'd1BIND_OUT')] + ) + @classmethod def define_tables(cls, metadata): class MyType(types.UserDefinedType):