summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/coercions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-12-09 11:39:45 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-12-11 15:39:46 -0500
commit4beecfb9040a7c202a8331b170cfd13119ddd7a3 (patch)
treeb2e8b2b3c9a7225a9dc5d5129a5860c7dc70867b /lib/sqlalchemy/sql/coercions.py
parent8e9e473dcb76b57a7f0eaa476481cb66a258ea69 (diff)
downloadsqlalchemy-4beecfb9040a7c202a8331b170cfd13119ddd7a3.tar.gz
Emit deprecation warnings for plain text under Session
Deprecation warnings are emitted under "SQLALCHEMY_WARN_20" mode when passing a plain string to :meth:`_orm.Session.execute`. It was also considered to have DDL string expressions to include this as well, however this leaves us with no backwards-compatible way of handling reflection of elemens, such as an Index() which reflects "postgresql_where='x > 5'", there's no place for a rule that will turn those into text() within the reflection process that would be separate from when the user passes postgresql_where to the Index. Not worth it right now. Fixes: #5754 Change-Id: I8673a79f0e87de0df576b655f39dad0351725ca8
Diffstat (limited to 'lib/sqlalchemy/sql/coercions.py')
-rw-r--r--lib/sqlalchemy/sql/coercions.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py
index 9b3acf5ad..bdd807438 100644
--- a/lib/sqlalchemy/sql/coercions.py
+++ b/lib/sqlalchemy/sql/coercions.py
@@ -682,6 +682,10 @@ class DDLExpressionImpl(_Deannotate, _CoerceLiterals, RoleImpl):
_coerce_consts = True
def _text_coercion(self, element, argname=None):
+ # see #5754 for why we can't easily deprecate this coercion.
+ # essentially expressions like postgresql_where would have to be
+ # text() as they come back from reflection and we don't want to
+ # have text() elements wired into the inspection dictionaries.
return elements.TextClause(element)
@@ -769,21 +773,6 @@ class StatementImpl(_NoTextCoercion, RoleImpl):
class CoerceTextStatementImpl(_CoerceLiterals, RoleImpl):
__slots__ = ()
- def _dont_literal_coercion(self, element, **kw):
- if callable(element) and hasattr(element, "__code__"):
- return lambdas.StatementLambdaElement(
- element,
- self._role_class,
- additional_cache_criteria=kw.get(
- "additional_cache_criteria", ()
- ),
- tracked=kw["tra"],
- )
- else:
- return super(CoerceTextStatementImpl, self)._literal_coercion(
- element, **kw
- )
-
def _implicit_coercions(
self, original_element, resolved, argname=None, **kw
):
@@ -795,8 +784,12 @@ class CoerceTextStatementImpl(_CoerceLiterals, RoleImpl):
)
def _text_coercion(self, element, argname=None):
- # TODO: this should emit deprecation warning,
- # see deprecation warning in engine/base.py execute()
+ util.warn_deprecated_20(
+ "Using plain strings to indicate SQL statements without using "
+ "the text() construct is "
+ "deprecated and will be removed in version 2.0. Ensure plain "
+ "SQL statements are passed using the text() construct."
+ )
return elements.TextClause(element)