Skip to content

Commit 9438962

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 <[email protected]> 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 eb231db commit 9438962

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/pl/plpython/expected/plpython_subtransaction.out

+7-4
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,11 @@ with plpy.subtransaction() as s:
236236
$$ LANGUAGE plpythonu;
237237
CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
238238
AS $$
239-
with plpy.subtransaction() as s:
240-
s.__exit__(None, None, None)
239+
try:
240+
with plpy.subtransaction() as s:
241+
s.__exit__(None, None, None)
242+
except ValueError as e:
243+
raise ValueError(e)
241244
$$ LANGUAGE plpythonu;
242245
SELECT subtransaction_exit_without_enter();
243246
ERROR: ValueError: this subtransaction has not been entered
@@ -289,8 +292,8 @@ PL/Python function "subtransaction_enter_subtransaction_in_with"
289292
SELECT subtransaction_exit_subtransaction_in_with();
290293
ERROR: ValueError: this subtransaction has already been exited
291294
CONTEXT: Traceback (most recent call last):
292-
PL/Python function "subtransaction_exit_subtransaction_in_with", line 3, in <module>
293-
s.__exit__(None, None, None)
295+
PL/Python function "subtransaction_exit_subtransaction_in_with", line 6, in <module>
296+
raise ValueError(e)
294297
PL/Python function "subtransaction_exit_subtransaction_in_with"
295298
-- Make sure we don't get a "current transaction is aborted" error
296299
SELECT 1 as test;

src/pl/plpython/sql/plpython_subtransaction.sql

+5-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ $$ LANGUAGE plpythonu;
158158

159159
CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
160160
AS $$
161-
with plpy.subtransaction() as s:
162-
s.__exit__(None, None, None)
161+
try:
162+
with plpy.subtransaction() as s:
163+
s.__exit__(None, None, None)
164+
except ValueError as e:
165+
raise ValueError(e)
163166
$$ LANGUAGE plpythonu;
164167

165168
SELECT subtransaction_exit_without_enter();

0 commit comments

Comments
 (0)