deltachat / mailadm

mail account administration tool for temporary and other account creation/modification
https://mailadm.readthedocs.io/
Mozilla Public License 2.0
14 stars 1 forks source link

python 3.12 and sqlite3: use `autocommit=False` #113

Open link2xt opened 1 year ago

link2xt commented 1 year ago

Python 3.12 is going to introduce new autocommit keyword argument for the connect() function. It does not exist in Python 3.11 and is set to LEGACY_TRANSACTION_CONTROL by default in Python 3.12, but it is recommended to set autocommit to False by the documentation.

If the recommended autocommit=False mode is used, we should not open our own transaction, while python will open DEFERRED transactions for us. Transactions should be committed with .commit() or rolled back with .rollback(). Because the transaction is DEFERRED, there is a possibility of .commit() failing, as far as I understand with an sqlite3.OperationalError, in which case the transaction should be retried from scratch as if it was rolled back.

Even if we do not switch to the new behaviour, we should not forget to set autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL explicitly on Python >= 3.12, because the documentation for it says "The default will change to False in a future Python release."