summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/coercions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-18 20:35:01 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-27 21:19:06 -0400
commit47552aa93bedcce3756dc89774f02db9f1868e68 (patch)
tree4a00be1f85b5964e8cf6d035ed94345eba0459e4 /lib/sqlalchemy/sql/coercions.py
parent8b2eb2a2d0f4c7e283d96cf3e5263b5dd48e3b14 (diff)
downloadsqlalchemy-47552aa93bedcce3756dc89774f02db9f1868e68.tar.gz
Use roles for ORM alias() conversion
as SELECT statements will have subquery() and not alias(), start getting ready for the places where the ORM coerces SELECTs into subqueries and be ready to warn about it Change-Id: I90d4b6cae2c72816c6b192016ce074589caf4731
Diffstat (limited to 'lib/sqlalchemy/sql/coercions.py')
-rw-r--r--lib/sqlalchemy/sql/coercions.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py
index 7c7222f9f..d4551eb60 100644
--- a/lib/sqlalchemy/sql/coercions.py
+++ b/lib/sqlalchemy/sql/coercions.py
@@ -199,7 +199,7 @@ def _no_text_coercion(
class _NoTextCoercion(object):
- def _literal_coercion(self, element, argname=None):
+ def _literal_coercion(self, element, argname=None, **kw):
if isinstance(element, util.string_types) and issubclass(
elements.TextClause, self._role_class
):
@@ -216,7 +216,7 @@ class _CoerceLiterals(object):
def _text_coercion(self, element, argname=None):
return _no_text_coercion(element, argname)
- def _literal_coercion(self, element, argname=None):
+ def _literal_coercion(self, element, argname=None, **kw):
if isinstance(element, util.string_types):
if self._coerce_star and element == "*":
return elements.ColumnClause("*", is_literal=True)
@@ -240,7 +240,9 @@ class _CoerceLiterals(object):
class ExpressionElementImpl(
_ColumnCoercions, RoleImpl, roles.ExpressionElementRole
):
- def _literal_coercion(self, element, name=None, type_=None, argname=None):
+ def _literal_coercion(
+ self, element, name=None, type_=None, argname=None, **kw
+ ):
if element is None:
return elements.Null()
else:
@@ -256,7 +258,7 @@ class BinaryElementImpl(
ExpressionElementImpl, RoleImpl, roles.BinaryElementRole
):
def _literal_coercion(
- self, element, expr, operator, bindparam_type=None, argname=None
+ self, element, expr, operator, bindparam_type=None, argname=None, **kw
):
try:
return expr._bind_param(operator, element, type_=bindparam_type)
@@ -393,7 +395,7 @@ class DMLColumnImpl(_ReturnsStringKey, RoleImpl, roles.DMLColumnRole):
class ConstExprImpl(RoleImpl, roles.ConstExprRole):
- def _literal_coercion(self, element, argname=None):
+ def _literal_coercion(self, element, argname=None, **kw):
if element is None:
return elements.Null()
elif element is False:
@@ -413,7 +415,7 @@ class TruncatedLabelImpl(_StringOnly, RoleImpl, roles.TruncatedLabelRole):
else:
self._raise_for_expected(original_element, argname)
- def _literal_coercion(self, element, argname=None):
+ def _literal_coercion(self, element, argname=None, **kw):
"""coerce the given value to :class:`._truncated_label`.
Existing :class:`._truncated_label` and
@@ -542,6 +544,34 @@ class FromClauseImpl(_NoTextCoercion, RoleImpl, roles.FromClauseRole):
self._raise_for_expected(original_element, argname)
+class StrictFromClauseImpl(FromClauseImpl, roles.StrictFromClauseRole):
+ def _implicit_coercions(
+ self,
+ original_element,
+ resolved,
+ argname=None,
+ allow_select=False,
+ **kw
+ ):
+ if resolved._is_select_statement and allow_select:
+ util.warn_deprecated(
+ "Implicit coercion of SELECT and textual SELECT constructs "
+ "into FROM clauses is deprecated; please call .subquery() "
+ "on any Core select or ORM Query object in order to produce a "
+ "subquery object."
+ )
+ return resolved.subquery()
+ else:
+ self._raise_for_expected(original_element, argname)
+
+
+class AnonymizedFromClauseImpl(
+ StrictFromClauseImpl, roles.AnonymizedFromClauseRole
+):
+ def _post_coercion(self, element, flat=False, **kw):
+ return element.alias(flat=flat)
+
+
class DMLSelectImpl(_NoTextCoercion, RoleImpl, roles.DMLSelectRole):
def _implicit_coercions(
self, original_element, resolved, argname=None, **kw