Get the transaction registered for the current thread.

        :return:
        :rtype: Transaction

def get_transaction(self, clear=False):
        """
        Get the transaction registered for the current thread.

        :return:
        :rtype: Transaction
        """
        transaction = getattr(self.thread_local, "transaction", None)
        if clear:
            self.thread_local.transaction = None
        return transaction