as_scalar() not called on Query based subquery in column context

Issue #2190 resolved
Mike Bayer repo owner created an issue

i.e.

s.query(Parent).filter(Parent.id==s.query(Child.id).filter(Child.name=='foo'))

will render the scalar subquery in the FROM clause.

we do this already for non ORM queries.

patch:

--- a/lib/sqlalchemy/sql/expression.py  Wed Jun 08 17:56:00 2011 -0400
+++ b/lib/sqlalchemy/sql/expression.py  Sun Jun 12 20:20:25 2011 -0400
@@ -1943,7 +1943,10 @@
             other.type = self.type
             return other
         elif hasattr(other, '__clause_element__'):
-            return other.__clause_element__()
+            other = other.__clause_element__()
+            if isinstance(other, (_SelectBase, Alias)):
+                other = other.as_scalar()
+            return other
         elif not isinstance(other, ClauseElement):
             return self._bind_param(operator, other)
         elif isinstance(other, (_SelectBase, Alias)):

Comments (2)

  1. Log in to comment