]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where :func:`.type_coerce` would not interpret ORM
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Oct 2013 19:06:41 +0000 (15:06 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Oct 2013 19:08:04 +0000 (15:08 -0400)
elements with a ``__clause_element__()`` method properly.
[ticket:2849]

Conflicts:
lib/sqlalchemy/sql/elements.py

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/expression.py
test/sql/test_types.py

index a6352a767c01c6aed622e5760ad5064bd1ad72ef..5aed2b7d8418be0e595e9404fbddb1af91ff3514 100644 (file)
 .. 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
index 837716a41ccd7ad3b27be22d50b5c3fcebbce18b..aa655f34fe72edbd07e9dd2f0c26031a219fb011 100644 (file)
@@ -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_
index b58175d60505e60d3169b36b0ed3a4768980cb4a..2556e8adc246c0db898f8672d98e0ad579e6b0f0 100644 (file)
@@ -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):