--- /dev/null
+.. change::
+ :tags: bug, regression, sql
+ :tickets: 6181
+
+ Fixed regression where use of the :meth:`.Operators.in_` method with a
+ :class:`_sql.Select` object against a non-table-bound column would produce
+ an ``AttributeError``, or more generally using a :class:`_sql.ScalarSelect`
+ that has no datatype in a binary expression would produce invalid state.
+
self.type = getattr(element, "type", type_api.NULLTYPE)
def _with_binary_element_type(self, type_):
- return Grouping(self.element._with_binary_element_type(type_))
+ return self.__class__(self.element._with_binary_element_type(type_))
@util.memoized_property
def _is_implicitly_boolean(self):
checkparams={"myid_1": [1, 2, 3]},
)
+ def test_scalar_subquery_wo_type(self):
+ """ test for :ticket:`6181` """
+
+ m = MetaData()
+ t = Table("t", m, Column("a", Integer))
+
+ # the scalar subquery of this will have no type; coercions will
+ # want to call _with_binary_element_type(); that has to return
+ # a scalar select
+ req = select(column("scan"))
+
+ self.assert_compile(
+ select(t.c.a).where(t.c.a.in_(req)),
+ "SELECT t.a FROM t WHERE t.a IN (SELECT scan)",
+ )
+
class MathOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = "default"
from sqlalchemy.sql.elements import _truncated_label
from sqlalchemy.sql.elements import Null
from sqlalchemy.sql.selectable import FromGrouping
+from sqlalchemy.sql.selectable import ScalarSelect
from sqlalchemy.sql.selectable import SelectStatementGrouping
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
)
)
+ def test_untyped_scalar_subquery(self):
+ """test for :ticket:`6181` """
+
+ c = column("q")
+ subq = select(c).scalar_subquery()
+
+ assert isinstance(
+ subq._with_binary_element_type(Integer()), ScalarSelect
+ )
+
+ expr = column("a", Integer) == subq
+ assert isinstance(expr.right, ScalarSelect)
+
def test_no_clauseelement_in_bind(self):
with testing.expect_raises_message(
exc.ArgumentError,