Skip to content

Commit

Permalink
Fix subtransaction test for Python 3.10
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petere committed Jun 17, 2021
1 parent eb231db commit 9438962
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/pl/plpython/expected/plpython_subtransaction.out
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ with plpy.subtransaction() as s:
$$ LANGUAGE plpythonu;
CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
AS $$
with plpy.subtransaction() as s:
s.__exit__(None, None, None)
try:
with plpy.subtransaction() as s:
s.__exit__(None, None, None)
except ValueError as e:
raise ValueError(e)
$$ LANGUAGE plpythonu;
SELECT subtransaction_exit_without_enter();
ERROR: ValueError: this subtransaction has not been entered
Expand Down Expand Up @@ -289,8 +292,8 @@ PL/Python function "subtransaction_enter_subtransaction_in_with"
SELECT subtransaction_exit_subtransaction_in_with();
ERROR: ValueError: this subtransaction has already been exited
CONTEXT: Traceback (most recent call last):
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 6, in <module>
raise ValueError(e)
PL/Python function "subtransaction_exit_subtransaction_in_with"
-- Make sure we don't get a "current transaction is aborted" error
SELECT 1 as test;
Expand Down
7 changes: 5 additions & 2 deletions src/pl/plpython/sql/plpython_subtransaction.sql
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ $$ LANGUAGE plpythonu;

CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
AS $$
with plpy.subtransaction() as s:
s.__exit__(None, None, None)
try:
with plpy.subtransaction() as s:
s.__exit__(None, None, None)
except ValueError as e:
raise ValueError(e)
$$ LANGUAGE plpythonu;

SELECT subtransaction_exit_without_enter();
Expand Down

0 comments on commit 9438962

Please sign in to comment.