]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
cache key share; support correct traverse of 'of'
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 Jun 2024 22:17:47 +0000 (18:17 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 Jun 2024 22:24:37 +0000 (18:24 -0400)
Fixed caching issue where the
:paramref:`_sql.Select.with_for_update.key_share` element of
:meth:`_sql.Select.with_for_update` was not considered as part of the cache
key, leading to incorrect caching if different variations of this parameter
were used with an otherwise identical statement.

Also repairs a traversal issue where the ``of`` element of
``ForUpdateArg`` when set to ``None`` cannot be compared against a
non-None element because the traversal defines it as a clauselist.
Traversal in this case is adjusted to accommodate for this case so that
we dont need to create a risky-to-backport change to ``ForUpdateArg``
itself.

Fixes: #11544
Change-Id: Ie8a50716df06977af58b0c22a8c10e1b64d972b9
(cherry picked from commit 6d2f43e14f2fe25cdc811355b7bd6d11f8eee381)
(cherry picked from commit 522baa306fc788cf02acf29bf08e86a431a7050e)

lib/sqlalchemy/sql/selectable.py
lib/sqlalchemy/sql/traversals.py
test/sql/test_compare.py

index 95d2fdf245a938f35848a41af3c79ef4497d82ab..7536665a6eabfcb0f3a9285880b5ecfd8c046107 100644 (file)
@@ -2831,6 +2831,7 @@ class ForUpdateArg(ClauseElement):
         ("nowait", InternalTraversal.dp_boolean),
         ("read", InternalTraversal.dp_boolean),
         ("skip_locked", InternalTraversal.dp_boolean),
+        ("key_share", InternalTraversal.dp_boolean),
     ]
 
     @classmethod
index 41b960c9c337f7bdec49d93c8e22a2652aeb5958..eb4913d7c332da5dac085f6f93aefdb14b584896 100644 (file)
@@ -1159,6 +1159,8 @@ class TraversalComparatorStrategy(InternalTraversal, util.MemoizedSlots):
                         return False
                     else:
                         continue
+                elif right_child is None:
+                    return False
 
                 comparison = dispatch(
                     left_attrname, left, left_child, right, right_child, **kw
index 0a7f0d4114dd8b0dce850ae60321580a69744f16..3e13174f79060888a544632277d76ac5266fbceb 100644 (file)
@@ -472,6 +472,21 @@ class CoreFixtures(object):
             select(table_a.c.a)
             .where(table_a.c.b == 5)
             .with_for_update(nowait=True),
+            select(table_a.c.a)
+            .where(table_a.c.b == 5)
+            .with_for_update(nowait=True, skip_locked=True),
+            select(table_a.c.a)
+            .where(table_a.c.b == 5)
+            .with_for_update(nowait=True, read=True),
+            select(table_a.c.a)
+            .where(table_a.c.b == 5)
+            .with_for_update(of=table_a.c.a),
+            select(table_a.c.a)
+            .where(table_a.c.b == 5)
+            .with_for_update(of=table_a.c.b),
+            select(table_a.c.a)
+            .where(table_a.c.b == 5)
+            .with_for_update(nowait=True, key_share=True),
             select(table_a.c.a).where(table_a.c.b == 5).correlate(table_b),
             select(table_a.c.a)
             .where(table_a.c.b == 5)