elements with a ``__clause_element__()`` method properly.
[ticket:2849]
Conflicts:
lib/sqlalchemy/sql/elements.py
.. 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
"""
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_
'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):