]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
apply _propagate_attrs in _construct_for_list
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 18 Feb 2025 15:20:32 +0000 (10:20 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 18 Feb 2025 17:01:33 +0000 (12:01 -0500)
Fixed issue where the "is ORM" flag of a :func:`.select` or other ORM
statement would not be propagated to the ORM :class:`.Session` based on a
multi-part operator expression alone, e.g. such as ``Cls.attr + Cls.attr +
Cls.attr`` or similar, leading to ORM behaviors not taking place for such
statements.

Fixes: #12357
Change-Id: I61130eeb3c7a32c1830731fd9ad4eb99a64abf7d
(cherry picked from commit d0873ec7735f8238d74b860d6a8a85d55b2dbd1d)

doc/build/changelog/unreleased_20/12357.rst [new file with mode: 0644]
lib/sqlalchemy/sql/elements.py
test/orm/test_core_compilation.py

diff --git a/doc/build/changelog/unreleased_20/12357.rst b/doc/build/changelog/unreleased_20/12357.rst
new file mode 100644 (file)
index 0000000..79fd888
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, orm
+    :tickets: 12357
+
+    Fixed issue where the "is ORM" flag of a :func:`.select` or other ORM
+    statement would not be propagated to the ORM :class:`.Session` based on a
+    multi-part operator expression alone, e.g. such as ``Cls.attr + Cls.attr +
+    Cls.attr`` or similar, leading to ORM behaviors not taking place for such
+    statements.
index 6f20d7efa0d0df521bb58e67f77f50d592e2d6ba..fde503aaf9bdf4f07cd6cf9ab15978b0a193ca87 100644 (file)
@@ -2977,6 +2977,10 @@ class ExpressionClauseList(OperatorExpression[_T]):
             self.clauses = clauses
         self.operator = operator
         self.type = type_
+        for c in clauses:
+            if c._propagate_attrs:
+                self._propagate_attrs = c._propagate_attrs
+                break
         return self
 
     def _negate(self) -> Any:
index 6af9185836b128cff0d1e10a49e7a0af24b7a7b5..a961962d916373644393f02e5897e33c4d370ccb 100644 (file)
@@ -368,6 +368,14 @@ class PropagateAttrsTest(QueryTest):
     def propagate_cases():
         return testing.combinations(
             (lambda: select(1), False),
+            (lambda User: select(User.id), True),
+            (lambda User: select(User.id + User.id), True),
+            (lambda User: select(User.id + User.id + User.id), True),
+            (lambda User: select(sum([User.id] * 10, User.id)), True),  # type: ignore  # noqa: E501
+            (
+                lambda User: select(literal_column("3") + User.id + User.id),
+                True,
+            ),
             (lambda User: select(func.count(User.id)), True),
             (
                 lambda User: select(1).select_from(select(User).subquery()),