Commit 01b42a7a authored by Vincent Pelletier's avatar Vincent Pelletier

storage: Forbid subtransactions.

...when connection is used as a context manager (which is the expected
coding style anyway).
If silently ignored, rollback may be incomplete if a subtransaction already
committed.
And if commit only happen at outmost transaction, no-undo changes could
come undone if outer transaction aborts.

This is currently observed in the code, so no other change is needed.
parent 6aec197a
...@@ -31,6 +31,19 @@ __all__ = ('SQLite3Storage', ) ...@@ -31,6 +31,19 @@ __all__ = ('SQLite3Storage', )
DAY_IN_SECONDS = 60 * 60 * 24 DAY_IN_SECONDS = 60 * 60 * 24
class NoReentryConnection(sqlite3.Connection):
__entered = False
def __enter__(self):
if self.__entered:
raise Exception('Subtransactions are not supported')
self.__entered = True
return super(NoReentryConnection, self).__enter__()
def __exit__(self, exc_type, exc_value, traceback):
self.__entered = False
return super(NoReentryConnection, self).__exit__(exc_type, exc_value, traceback)
class SQLite3Storage(local): class SQLite3Storage(local):
""" """
CA data storage. CA data storage.
...@@ -80,7 +93,7 @@ class SQLite3Storage(local): ...@@ -80,7 +93,7 @@ class SQLite3Storage(local):
os.O_CREAT | os.O_RDONLY, os.O_CREAT | os.O_RDONLY,
mode, mode,
)) ))
self._db = db = sqlite3.connect(db_path) self._db = db = sqlite3.connect(db_path, factory=NoReentryConnection)
self._table_prefix = table_prefix self._table_prefix = table_prefix
db.row_factory = sqlite3.Row db.row_factory = sqlite3.Row
self._max_csr_amount = max_csr_amount self._max_csr_amount = max_csr_amount
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment