This warning will in a later major release become an error, however the
message will always be clear when :meth:`.SelectBase.scalar_subquery` needs
to be invoked. The latter part of the change is for clarity and to reduce
- the implicit decisionmaking by the query coercion system.
+ the implicit decisionmaking by the query coercion system. The
+ :meth:`.Subquery.as_scalar` method, which was previously
+ ``Alias.as_scalar``, is also deprecated; ``.scalar_subquery()`` should be
+ invoked directly from ` :func:`.select` object or :class:`.Query` object.
This change is part of the larger change to convert :func:`.select` objects
to no longer be directly part of the "from clause" class hierarchy, which
roles.SelectStatementRole, selectable
).subquery(name=name)
+ @util.deprecated(
+ "1.4",
+ "The :meth:`.Subquery.as_scalar` method, which was previously "
+ "``Alias.as_scalar()`` prior to version 1.4, is deprecated and "
+ "will be removed in a future release; Please use the "
+ ":meth:`.Select.scalar_subquery` method of the :func:`.select` "
+ "construct before constructing a subquery object, or with the ORM "
+ "use the :meth:`.Query.scalar_subquery` method.",
+ )
+ def as_scalar(self):
+ return self.element.scalar_subquery()
+
class FromGrouping(GroupedElement, FromClause):
"""Represent a grouping of a FROM clause"""
is_true(stmt.compare(select([self.table1.c.myid]).scalar_subquery()))
+ def test_as_scalar_from_subquery(self):
+ with testing.expect_deprecated(
+ r"The Subquery.as_scalar\(\) method, which was previously "
+ r"``Alias.as_scalar\(\)`` prior to version 1.4"
+ ):
+ stmt = select([self.table1.c.myid]).subquery().as_scalar()
+
+ is_true(stmt.compare(select([self.table1.c.myid]).scalar_subquery()))
+
def test_fromclause_subquery(self):
stmt = select([self.table1.c.myid])
with testing.expect_deprecated(