Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21630d2

Browse files
committed
consolidate kwargs for "FOR UPDATE OF"
Fixed compiler issue in the PostgreSQL dialect where incorrect keywords would be passed when using "FOR UPDATE OF" inside of a subquery. Fixes: sqlalchemy#12417 Change-Id: I6255d165e8e719e1786e78aa60ee8e6a95af1dcb
1 parent dfc3bf9 commit 21630d2

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. change::
2+
:tags: bug, postgresql
3+
:tickets: 12417
4+
5+
Fixed compiler issue in the PostgreSQL dialect where incorrect keywords
6+
would be passed when using "FOR UPDATE OF" inside of a subquery.

lib/sqlalchemy/dialects/postgresql/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,9 +2001,10 @@ def for_update_clause(self, select, **kw):
20012001
for c in select._for_update_arg.of:
20022002
tables.update(sql_util.surface_selectables_only(c))
20032003

2004+
of_kw = dict(kw)
2005+
of_kw.update(ashint=True, use_schema=False)
20042006
tmp += " OF " + ", ".join(
2005-
self.process(table, ashint=True, use_schema=False, **kw)
2006-
for table in tables
2007+
self.process(table, **of_kw) for table in tables
20072008
)
20082009

20092010
if select._for_update_arg.nowait:

test/dialect/postgresql/test_compiler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,15 @@ def test_for_update(self):
17331733
"FOR UPDATE OF table1",
17341734
)
17351735

1736+
# test issue #12417
1737+
subquery = select(table1.c.myid).with_for_update(of=table1).lateral()
1738+
statement = select(subquery.c.myid)
1739+
self.assert_compile(
1740+
statement,
1741+
"SELECT anon_1.myid FROM LATERAL (SELECT mytable.myid AS myid "
1742+
"FROM mytable FOR UPDATE OF mytable) AS anon_1",
1743+
)
1744+
17361745
def test_for_update_with_schema(self):
17371746
m = MetaData()
17381747
table1 = Table(

0 commit comments

Comments
 (0)