kvesteri / sqlalchemy-continuum

Versioning extension for SQLAlchemy.
BSD 3-Clause "New" or "Revised" License
568 stars 128 forks source link

when autocommit isolation mode used, rollback at transaction level is not resulting in rollback of continuum transactions #333

Closed chicco785 closed 1 year ago

chicco785 commented 1 year ago

as described in the title, when on an engine connection we configure connection.execution_options(isolation_level="AUTOCOMMIT") in case of transaction rollback, continuum related transactions are not removed from the database.

marksteward commented 1 year ago

Does this only affect SQLAlchemy 1.4 or above in future mode? Can you share some code to reproduce it?

chicco785 commented 1 year ago

I am currently using SQLAlchemy 2.0 and continuum 1.4 version, i will try to provide you a minimal snipped of code to demo it (i need to extract it from my code)

marksteward commented 1 year ago

Also which DBMS are you using? I don't really understand what rollback for autocommit would even mean.

chicco785 commented 1 year ago

i am testing it with 3 databases:

All exhibit the same issue, so it's not related to a specific dbms. You can enable autocommit isolation level (for psql and sqlite, for mysql is a bit more tricky) as follows:

engine = create_engine("postgresql+pg8000://postgres:postgres@localhost:5432/test")
connection = engine.connect()
connection.execution_options(isolation_level="AUTOCOMMIT")
transaction = connection.begin()
session = Session(bind=connection)

then, if instead of committing the transaction, you roll it back:

session.close()
# roll back the broader transaction
transaction.rollback()
# put back the connection to the connection pool
connection.close()

while changes to my tables are correctly rolled back, transactions table created by continuum is still populated with transactions that actually never occurred, since we rolled them back.

marksteward commented 1 year ago

connection.begin should be a no-op under isolation_level="AUTOCOMMIT". You should see warnings in the logs to say so.

marksteward commented 1 year ago

I'm guessing you don't actually need autocommit semantics, but if you do, have a look at the native versioning plugin.

chicco785 commented 1 year ago

thx