diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2019-09-11 15:10:16 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2019-09-11 15:10:16 +0000 |
| commit | 7986a654a84bf6887394a8b908568a7406cd445a (patch) | |
| tree | 036e532e95e43980a0e0870f132c72cf12613ab5 | |
| parent | edcfc262a33bf8cbe509f2640e55d3361232c185 (diff) | |
| parent | 3b85eeb5d2e662141139ad54ccaad5df24ad9b7d (diff) | |
| download | sqlalchemy-7986a654a84bf6887394a8b908568a7406cd445a.tar.gz | |
Merge "Restore subquery.as_scalar() w/ deprecation"
| -rw-r--r-- | doc/build/changelog/unreleased_14/4617_scalar.rst | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 12 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 9 |
3 files changed, 25 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_14/4617_scalar.rst b/doc/build/changelog/unreleased_14/4617_scalar.rst index d47b3e464..6fb4adcca 100644 --- a/doc/build/changelog/unreleased_14/4617_scalar.rst +++ b/doc/build/changelog/unreleased_14/4617_scalar.rst @@ -13,7 +13,10 @@ 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 diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 00d3826b2..166e592b6 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1753,6 +1753,18 @@ class Subquery(AliasedReturnsRows): 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""" diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index d126912a5..09deb1294 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -579,6 +579,15 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): 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( |
