Skip to content

Commit 4a682d8

Browse files
committed
Fix subtransaction test for Python 3.10
Starting with Python 3.10, the stacktrace looks differently: - PL/Python function "subtransaction_exit_subtransaction_in_with", line 3, in <module> - s.__exit__(None, None, None) + PL/Python function "subtransaction_exit_subtransaction_in_with", line 2, in <module> + with plpy.subtransaction() as s: Using try/except specifically makes the error look always the same. (See python/cpython#25719 for the discussion of this change in Python.) Author: Honza Horak <hhorak@redhat.com> Discussion: https://www.postgresql.org/message-id/flat/853083.1620749597%40sss.pgh.pa.us RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1959080
1 parent f61db90 commit 4a682d8

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/pl/plpython/expected/plpython_subtransaction.out

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ with plpy.subtransaction() as s:
171171
$$ LANGUAGE plpythonu;
172172
CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
173173
AS $$
174-
with plpy.subtransaction() as s:
175-
s.__exit__(None, None, None)
174+
try:
175+
with plpy.subtransaction() as s:
176+
s.__exit__(None, None, None)
177+
except ValueError as e:
178+
raise ValueError(e)
176179
$$ LANGUAGE plpythonu;
177180
SELECT subtransaction_exit_without_enter();
178181
ERROR: ValueError: this subtransaction has not been entered
@@ -224,8 +227,8 @@ PL/Python function "subtransaction_enter_subtransaction_in_with"
224227
SELECT subtransaction_exit_subtransaction_in_with();
225228
ERROR: ValueError: this subtransaction has already been exited
226229
CONTEXT: Traceback (most recent call last):
227-
PL/Python function "subtransaction_exit_subtransaction_in_with", line 3, in <module>
228-
s.__exit__(None, None, None)
230+
PL/Python function "subtransaction_exit_subtransaction_in_with", line 6, in <module>
231+
raise ValueError(e)
229232
PL/Python function "subtransaction_exit_subtransaction_in_with"
230233
-- Make sure we don't get a "current transaction is aborted" error
231234
SELECT 1 as test;

src/pl/plpython/sql/plpython_subtransaction.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ $$ LANGUAGE plpythonu;
121121

122122
CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
123123
AS $$
124-
with plpy.subtransaction() as s:
125-
s.__exit__(None, None, None)
124+
try:
125+
with plpy.subtransaction() as s:
126+
s.__exit__(None, None, None)
127+
except ValueError as e:
128+
raise ValueError(e)
126129
$$ LANGUAGE plpythonu;
127130

128131
SELECT subtransaction_exit_without_enter();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy