]> 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:06:41 +0000 (15:06 -0400)
elements with a ``__clause_element__()`` method properly.
[ticket:2849]

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

index 727931f9aa629b521d4f4b924dbdcc83348a3e3e..ab36c76f86f76f0255ec4833c18e38a936fdec1b 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 f70496418f0f768bf7766782141a383572be1fc2..251102d59c24ae29cd2d0014293630b039daa17e 100644 (file)
@@ -117,8 +117,8 @@ def type_coerce(expr, type_):
     """
     type_ = type_api.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 a2791ee29a6ce0711a7ab2e0e8a6fe7432fca64b..f739707f3a51d398e275a0e8c6303fba8c7a2f7e 100644 (file)
@@ -466,6 +466,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):