def process_view(self, request, view_func, view_args, view_kwargs): # This uses undocumented django APIS: # - transaction.get_connection() followed by in_atomic_block property, # which we need to make sure we're not messing with a transaction # that has already started (which happens in tests using the regular # TestCase class) # - _non_atomic_requests(), which set the property to prevent the # transaction on the view itself. We can't use non_atomic_requests # (without the '_') as it returns a *new* view, and we can't do that # in a middleware, we need to modify it in place and return None so # that the rest of the middlewares are run. is_method_safe = request.method in ('HEAD', 'GET', 'OPTIONS', 'TRACE') if is_method_safe and not transaction.get_connection().in_atomic_block: transaction._non_atomic_requests(view_func, using='default') return None
def process_view(self, request, view_func, view_args, view_kwargs): # This uses undocumented django APIS: # - transaction.get_connection() followed by in_atomic_block property, # which we need to make sure we're not messing with a transaction # that has already started (which happens in tests using the regular # TestCase class) # - _non_atomic_requests(), which set the property to prevent the # transaction on the view itself. We can't use non_atomic_requests # (without the '_') as it returns a *new* view, and we can't do that # in a middleware, we need to modify it in place and return None so # that the rest of the middlewares are run. is_method_safe = request.method in ('HEAD', 'GET', 'OPTIONS', 'TRACE') if is_method_safe and not transaction.get_connection().in_atomic_block: transaction._non_atomic_requests(view_func, using='default') return None