--- /dev/null
+.. change::
+ :tags: sql
+ :tickets: 12218
+
+ Removed the automatic coercion of executable objects, such as
+ :class:`_orm.Query`, when passed into :meth:`_orm.Session.execute`.
+ This usage raised a deprecation warning since the 1.4 series.
"""
def __init__(self, target: Any):
- super().__init__("Not an executable object: %r" % target)
+ super().__init__(f"Not an executable object: {target!r}")
self.target = target
def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
if resolved is not original_element and not isinstance(
original_element, str
):
- # use same method as Connection uses; this will later raise
- # ObjectNotExecutableError
+ # use same method as Connection uses
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",
- )
+ except AttributeError as err:
+ raise exc.ObjectNotExecutableError(original_element) from err
return resolved
q = Session().query(literal_column("1"))
- if executor == "session":
- with testing.expect_deprecated(
- r"Object .*Query.* should not be used directly in a "
- r"SQL statement context"
- ):
- meth(q)
- else:
- with testing.expect_raises_message(
- sa_exc.ObjectNotExecutableError, "Not an executable object"
- ):
- meth(q)
+ with testing.expect_raises_message(
+ sa_exc.ObjectNotExecutableError, "Not an executable object: .*"
+ ):
+ meth(q)
class OnlyReturnTuplesTest(QueryTest):