]> 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:39:03 +0000 (08:39 -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
(cherry picked from commit 21630d2574328a0f01a1e994e264f56f1adf99db)

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 318da6d67b2370f272faf560cb7caa4b1d1e0d4b..ca2a3fa59eff8839995ba6f03e911fcbbe6a19d6 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 f02b42c0b21bbdad276c9ab601a3492721b92c6c..55a43d20d1e85b57c2a9a51bcf32f06936e59547 100644 (file)
@@ -1731,6 +1731,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(