summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/coercions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-06-01 19:11:19 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-06-01 19:11:19 -0400
commit3d99ee28ed368c3bdbeaf872ef65b0c9a7c0da33 (patch)
tree6ab9a88793821d16bd573a516a4fbf55d358a453 /lib/sqlalchemy/sql/coercions.py
parentb05c8a0ef8b6e7bfd169a21e7c1f834fdb00da19 (diff)
downloadsqlalchemy-3d99ee28ed368c3bdbeaf872ef65b0c9a7c0da33.tar.gz
Refine IN and scalar subquery coercions
Ensure IN emits a warning when it coerces a FromClause into a select(), however that it continues to allow the scalar_subquery() coercion to be automatic, particularly since it's not clear that "col IN (select)" is necessarily "scalar" in the case of tuples. Convert the "scalar_subquery()" warning emitted in other cases to be a warning, rather than a deprecation warning. I can't imagine taking this coercion out as it is intuitive and is always going to happen; we just would like to note that an implicit coercion is occurring. Fixes: #5369 Change-Id: I748f01f40bc85c64e2776f9b88ef35641fa8fb5c
Diffstat (limited to 'lib/sqlalchemy/sql/coercions.py')
-rw-r--r--lib/sqlalchemy/sql/coercions.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py
index 7503faf5b..db43e42a6 100644
--- a/lib/sqlalchemy/sql/coercions.py
+++ b/lib/sqlalchemy/sql/coercions.py
@@ -211,13 +211,10 @@ class _ColumnCoercions(object):
__slots__ = ()
def _warn_for_scalar_subquery_coercion(self):
- util.warn_deprecated(
- "coercing SELECT object to scalar subquery in a "
- "column-expression context is deprecated in version 1.4; "
+ util.warn(
+ "implicitly coercing SELECT object to scalar subquery; "
"please use the .scalar_subquery() method to produce a scalar "
- "subquery. This automatic coercion will be removed in a "
- "future release.",
- version="1.4",
+ "subquery.",
)
def _implicit_coercions(
@@ -368,12 +365,21 @@ class InElementImpl(RoleImpl):
isinstance(resolved, selectable.Alias)
and resolved.element._is_select_statement
):
- return resolved.element
+ self._warn_for_implicit_coercion(resolved)
+ return self._post_coercion(resolved.element, **kw)
else:
- return resolved.select()
+ self._warn_for_implicit_coercion(resolved)
+ return self._post_coercion(resolved.select(), **kw)
else:
self._raise_for_expected(original_element, argname, resolved)
+ def _warn_for_implicit_coercion(self, elem):
+ util.warn(
+ "Coercing %s object into a select() for use in IN(); "
+ "please pass a select() construct explicitly"
+ % (elem.__class__.__name__)
+ )
+
def _literal_coercion(self, element, expr, operator, **kw):
if isinstance(element, collections_abc.Iterable) and not isinstance(
element, util.string_types
@@ -407,6 +413,8 @@ class InElementImpl(RoleImpl):
def _post_coercion(self, element, expr, operator, **kw):
if element._is_select_statement:
+ # for IN, we are doing scalar_subquery() coercion without
+ # a warning
return element.scalar_subquery()
elif isinstance(element, elements.ClauseList):
assert not len(element.clauses) == 0