]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
consolidate kwargs for "FOR UPDATE OF"
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 11 Mar 2025 12:33:30 +0000 (08:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 11 Mar 2025 12:36:18 +0000 (08:36 -0400)
Fixed compiler issue in the PostgreSQL dialect where incorrect keywords
would be passed when using "FOR UPDATE OF" inside of a subquery.

Fixes: #12417
Change-Id: I6255d165e8e719e1786e78aa60ee8e6a95af1dcb

doc/build/changelog/unreleased_20/12417.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_compiler.py

diff --git a/doc/build/changelog/unreleased_20/12417.rst b/doc/build/changelog/unreleased_20/12417.rst
new file mode 100644 (file)
index 0000000..b9b22a8
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 12417
+
+    Fixed compiler issue in the PostgreSQL dialect where incorrect keywords
+    would be passed when using "FOR UPDATE OF" inside of a subquery.
index e640e2a4cd5502470b4c9ca0c86a354e0e0bfcad..1f00127bfa63e2ca16751b5aeb2eea2c81271680 100644 (file)
@@ -2001,9 +2001,10 @@ class PGCompiler(compiler.SQLCompiler):
             for c in select._for_update_arg.of:
                 tables.update(sql_util.surface_selectables_only(c))
 
+            of_kw = dict(kw)
+            of_kw.update(ashint=True, use_schema=False)
             tmp += " OF " + ", ".join(
-                self.process(table, ashint=True, use_schema=False, **kw)
-                for table in tables
+                self.process(table, **of_kw) for table in tables
             )
 
         if select._for_update_arg.nowait:
index b6bd6257088dd3420de4e6e4be2fbbaed4d1929c..8e241b82e5879e61430bf666fd04e6ce376ef62e 100644 (file)
@@ -1733,6 +1733,15 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
             "FOR UPDATE OF table1",
         )
 
+        # test issue #12417
+        subquery = select(table1.c.myid).with_for_update(of=table1).lateral()
+        statement = select(subquery.c.myid)
+        self.assert_compile(
+            statement,
+            "SELECT anon_1.myid FROM LATERAL (SELECT mytable.myid AS myid "
+            "FROM mytable FOR UPDATE OF mytable) AS anon_1",
+        )
+
     def test_for_update_with_schema(self):
         m = MetaData()
         table1 = Table(