我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.db.transaction.leave_transaction_management()。
def set_rollback(): if hasattr(transaction, 'set_rollback'): if connection.settings_dict.get('ATOMIC_REQUESTS', False): # If running in >=1.6 then mark a rollback as required, # and allow it to be handled by Django. if connection.in_atomic_block: transaction.set_rollback(True) elif transaction.is_managed(): # Otherwise handle it explicitly if in managed mode. if transaction.is_dirty(): transaction.rollback() transaction.leave_transaction_management() else: # transaction not managed pass
def process_response(selfself, request, response): if transaction.is_managed(): if transaction.is_dirty(): successful = not isinstance(response, http.HttpApplicationError) if successful: transaction.commit() else: transaction.rollback() transaction.leave_transaction_management() return response