diff options
author | Federico Caselli <cfederico87@gmail.com> | 2021-10-01 22:16:14 +0200 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-10-04 14:33:29 -0400 |
commit | 3f2209776183193552cbc9516710deb6598fd6cd (patch) | |
tree | b86ec0e0a8f0f77c12c8ed2857e199d67d747da6 /lib/sqlalchemy/sql/coercions.py | |
parent | 71e463506217e3acc379a3f459e68a81792a0aac (diff) | |
download | sqlalchemy-3f2209776183193552cbc9516710deb6598fd6cd.tar.gz |
Warn when trying to execute a query object with a session.
Passing a :class:`.Query` object to :meth:`_orm.Session.execute` is not
the intended use of this object, and will now raise a deprecation warning.
Fixes: #6284
Change-Id: I30a406d5a72335f9405f10f0a2030a32ccda41b9
Diffstat (limited to 'lib/sqlalchemy/sql/coercions.py')
-rw-r--r-- | lib/sqlalchemy/sql/coercions.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py index dce329352..f888bad4c 100644 --- a/lib/sqlalchemy/sql/coercions.py +++ b/lib/sqlalchemy/sql/coercions.py @@ -191,7 +191,6 @@ def expect( resolved = element else: resolved = element - if ( apply_propagate_attrs is not None and not apply_propagate_attrs._propagate_attrs @@ -843,6 +842,28 @@ class ReturnsRowsImpl(RoleImpl): class StatementImpl(_CoerceLiterals, RoleImpl): __slots__ = () + def _post_coercion(self, resolved, original_element, argname=None, **kw): + if resolved is not original_element and not isinstance( + original_element, util.string_types + ): + # use same method as Connection uses; this will later raise + # ObjectNotExecutableError + try: + original_element._execute_on_connection + except AttributeError: + util.warn_deprecated( + "Object %r should not be used directly in a SQL statement " + "context, such as passing to methods such as " + "session.execute(). This usage will be disallowed in a " + "future release. " + "Please use Core select() / update() / delete() etc. " + "with Session.execute() and other statement execution " + "methods." % original_element, + "1.4", + ) + + return resolved + def _implicit_coercions( self, original_element, resolved, argname=None, **kw ): |