]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Removed executable coercion
authorFederico Caselli <cfederico87@gmail.com>
Sat, 4 Jan 2025 09:21:08 +0000 (10:21 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 23 Jan 2025 20:53:55 +0000 (21:53 +0100)
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.

Fixes: #12218
Change-Id: Iaab3116fcc8d957ff3f14e84a4ece428fd176b8b

doc/build/changelog/unreleased_21/12218.rst [new file with mode: 0644]
lib/sqlalchemy/exc.py
lib/sqlalchemy/sql/coercions.py
test/orm/test_query.py

diff --git a/doc/build/changelog/unreleased_21/12218.rst b/doc/build/changelog/unreleased_21/12218.rst
new file mode 100644 (file)
index 0000000..98ab995
--- /dev/null
@@ -0,0 +1,7 @@
+.. 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.
index c66124d6c8d6c621fa9acdf0852335e4c1aa4b49..077844c3c2b446f9a2557fa235aa88863acf3830 100644 (file)
@@ -139,7 +139,7 @@ class ObjectNotExecutableError(ArgumentError):
     """
 
     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, ...]]:
index 7119ae1c1f56fd4f7f3dcb9256293b0be53a9c4f..acbecb82291a67a52e4a4bd413f9196426741975 100644 (file)
@@ -1167,21 +1167,11 @@ class StatementImpl(_CoerceLiterals, RoleImpl):
         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
 
index 88e76e7c38a60873613cf64294963a06f9d74298..a2e78041dd221664f0e4f1d74831fef90af81f81 100644 (file)
@@ -160,17 +160,10 @@ class MiscTest(QueryTest):
 
         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):