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)
Leaves transaction management for a running thread. A dirty flag is carried
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/Django-1.6.10/django/db/backends/__init__.py/BaseDatabaseWrapper.leave_transaction_management