'Enters transaction management for a running thread. It must be balanced with
the appropriate leave_transaction_management call, since the actual state is
managed as a stack.
The state and dirty flag are carried over from the surrounding block or
from the settings, if there is no surrounding block (dirty is always false
when no current block is running).
If you switch off transaction management and there is a pending
commit/rollback, the data will be commited, unless "forced" is True.'

def enter_transaction_management(self, managed=True, forced=False):

    self.validate_no_atomic_block()
    self.transaction_state.append(managed)
    if ((not managed) and self.is_dirty() and (not forced)):
        self.commit()
        self.set_clean()
    if (managed == self.get_autocommit()):
        self.set_autocommit((not managed))
