Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression in transaction behavior in 1.29.0, savepoints now impossible #111

Closed
zzzeek opened this issue May 22, 2022 · 2 comments
Closed

Comments

@zzzeek
Copy link
Contributor

zzzeek commented May 22, 2022

hey there -

I tried to see if there were maybe ways to work around this in our test suite but actually there's not, the change at b2c5d6f prevents any SQL whatsoever from being emitted including ROLLBACK TO SAVEPOINT, which is the usual way we deal with being able to have database errors handled without rolling back the entire transaction.

PostgreSQL already ignores invalid commands in transaction blocks so if it were me, I'd fully revert this behavior; no other DBAPI does this. I see a rationale at #36 but this is not something any other PG driver does, psycopg2, psycopg3, asyncpg, etc. It's not a problem to be solved by the driver.

in the example below, we wish to use SAVEPOINT to emit SQL that might fail. with the new change, we are unable to ROLLBACK TO SAVEPOINT when the failure occurs.

import pg8000 as dbapi


conn = dbapi.connect(user="scott", password="tiger", host="localhost", database="test")


cursor = conn.cursor()

cursor.execute("SAVEPOINT sa_1")
try:
    cursor.execute("delete from nonexistent")
except:
    pass

cursor.execute("ROLLBACK TO SAVEPOINT sa_1")

output:

Traceback (most recent call last):
  File "/home/classic/dev/sqlalchemy/test3.py", line 15, in <module>
    cursor.execute("ROLLBACK TO SAVEPOINT sa_1")
  File "/home/classic/.venv3/lib/python3.10/site-packages/pg8000/legacy.py", line 251, in execute
    self._context = self._c.execute_simple(operation)
  File "/home/classic/.venv3/lib/python3.10/site-packages/pg8000/core.py", line 659, in execute_simple
    self.handle_messages(context)
  File "/home/classic/.venv3/lib/python3.10/site-packages/pg8000/core.py", line 813, in handle_messages
    raise context.error
pg8000.exceptions.InterfaceError: in failed transaction block

sqlalchemy-bot pushed a commit to sqlalchemy/sqlalchemy that referenced this issue May 22, 2022
Issue at tlocke/pg8000#111
prevents savepoints from being usable.

Change-Id: Ic689cf065c47aea5a146d30c47eb9bbfe8375692
(cherry picked from commit 8ec9317)
sqlalchemy-bot pushed a commit to sqlalchemy/sqlalchemy that referenced this issue May 22, 2022
Issue at tlocke/pg8000#111
prevents savepoints from being usable.

Change-Id: Ic689cf065c47aea5a146d30c47eb9bbfe8375692
@tlocke
Copy link
Owner

tlocke commented May 23, 2022

Hi @zzzeek, thanks for spotting this. I've quickly done release 1.29.1 that should allow ROLLBACK TO SAVEPOINT. I'll have a think about what to do in the longer term when I've got a bit more time.

@zzzeek
Copy link
Contributor Author

zzzeek commented May 23, 2022

OK, thanks for that. I can now see the pg8000 error providing cover for PostgreSQL transactions that are aborted in any case, so I guess it's a good thing even though i have to fix more things in our test suite.

sqlalchemy-bot pushed a commit to sqlalchemy/sqlalchemy that referenced this issue May 25, 2022
ROLLBACK TO SAVEPOINT is re-enabled
in tlocke/pg8000#111.

we still have to add savepoint support to our fixture that
deletes from tables without checking for them.
this is inconvenient but not incorrect.

Change-Id: I2f4a0a3e18db93c3e6794ade9b0fee33d2e4b7dc
sqlalchemy-bot pushed a commit to sqlalchemy/sqlalchemy that referenced this issue May 25, 2022
ROLLBACK TO SAVEPOINT is re-enabled
in tlocke/pg8000#111.

we still have to add savepoint support to our fixture that
deletes from tables without checking for them.
this is inconvenient but not incorrect.

Change-Id: I2f4a0a3e18db93c3e6794ade9b0fee33d2e4b7dc
(cherry picked from commit c0612f8)
@tlocke tlocke closed this as completed Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants