ensure all add account insert statements occur within a transaction
parent
44cf4e9e6f
commit
65d19a147d
|
@ -17,13 +17,18 @@ def _encrypt_password(password):
|
||||||
|
|
||||||
class AccountRepository(object):
|
class AccountRepository(object):
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
|
self.db = db
|
||||||
self.cursor = Cursor(db)
|
self.cursor = Cursor(db)
|
||||||
|
|
||||||
def add(self, account: Account, password: str):
|
def add(self, account: Account, password: str):
|
||||||
account.id = self._add_account(account, password)
|
prev_autocommit = self.db.autocommit
|
||||||
self._add_agreement(account)
|
self.db.autocommit = False
|
||||||
if account.subscription is not None:
|
with self.db:
|
||||||
self._add_subscription(account)
|
account.id = self._add_account(account, password)
|
||||||
|
self._add_agreement(account)
|
||||||
|
if account.subscription is not None:
|
||||||
|
self._add_subscription(account)
|
||||||
|
self.db.autocommit = prev_autocommit
|
||||||
|
|
||||||
def _add_account(self, account: Account, password: str):
|
def _add_account(self, account: Account, password: str):
|
||||||
"""Add a row to the account table."""
|
"""Add a row to the account table."""
|
||||||
|
|
Loading…
Reference in New Issue