chris chris - 6 months ago 15
Python Question

Is it possible to check for db updates before performing db.rollback() within a worker transaction?

I'm using a queue to queue transactions for a MySQL database in python. I'm using autocommit=False so that I can rollback a transaction if not all of the data queries are executed properly.

I'm wondering whether it's possible to check whether a worker has performed an action on the database before performing db.rollback()? Or can you perform db.rollback even if a worker hasn't done anything to the database without any errors occurring?

Thanks!

Answer

If I've understood the question correctly, it is not an error to rollback a transaction where nothing else has happened, although it is an error to attempt to rollback when no transaction exists. To tell which is the case you can test the MySQLConnection.in_transaction property.

Comments