view is not always executed

request will be recorded by the middleware and executed in async view, but in some cases, it will not be executed in view.


Python: 3.10.12

Django: 4.2.1

middleware settings:



class RequestMiddleware(MiddlewareMixin):
    def process_view(self, request, view_func, view_args, view_kwargs):
        req_str = "reqeust user:{} request method:{} request path:{} request body:{}".format(
        return None

    def process_response(self, request, response):
        data = response.content
        data = data.decode("utf-8")"response status code:{} data:{}".format(response.status_code, data))
        return response

    def process_exception(self, request, exception):

async def report(request):
    my_views.delay()  # celery task
    return send_message({"result": 0})

Welcome @AhaozZ !

Can you be more specific and provide more details about the issue you’re facing here? I’m not sure I understand what you’re asking or what information you’re looking for from us.

Hi Ken!
In prod environment, RequestMiddleware can log information for each request, but having an async view does not always work. Most of the time, it can work normally, but sometimes it may not work. I cannot reproduce this situation when using jemter for testing in the testing environment.
I try to log something in this view:

async def report(request):"request:{request.body} start work")
    my_views.delay()  # celery task
    return send_message({"result": 0})

There are some requests in the log that have not been recorded.