'Leaves transaction management for a running thread. A dirty flag is carried
over to the surrounding block, as a commit will commit all changes, even
those from outside. (Commits are on connection level.)'

def leave_transaction_management(self):

    self.validate_no_atomic_block()
    if self.transaction_state:
        del self.transaction_state[(-1)]
    else:
        raise TransactionManagementError("This    code    isn't    under    transaction    management")
    if self.transaction_state:
        managed = self.transaction_state[(-1)]
    else:
        managed = (not self.settings_dict['AUTOCOMMIT'])
    if self._dirty:
        self.rollback()
        if (managed == self.get_autocommit()):
            self.set_autocommit((not managed))
        raise TransactionManagementError('Transaction    managed    block    ended    with    pending    COMMIT/ROLLBACK')
    if (managed == self.get_autocommit()):
        self.set_autocommit((not managed))
