django-cprofile-middleware icon indicating copy to clipboard operation
django-cprofile-middleware copied to clipboard

'ProfilerMiddleware' object has no attribute 'profiler'

Open AzikDeveloper opened this issue 3 years ago • 3 comments

    def process_response(self, request, response):

        if self.can(request):

            self.profiler.create_stats()

 

AzikDeveloper avatar Nov 20 '21 16:11 AzikDeveloper

@omarish this error pops up every now and then, can you maybe have a look? Unfortunately I cannot get this 100% reproducable. However this PR looks promising: https://github.com/omarish/django-cprofile-middleware/pull/23. - Thx :)

backend_1      | Traceback (most recent call last):
backend_1      |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
backend_1      |     response = get_response(request)
backend_1      |   File "/usr/local/lib/python3.9/site-packages/django/utils/deprecation.py", line 119, in __call__
backend_1      |     response = self.process_response(request, response)
backend_1      |   File "/usr/local/lib/python3.9/site-packages/django_cprofile_middleware/middleware.py", line 67, in process_response
backend_1      |     self.profiler.create_stats()
backend_1      | AttributeError: 'ProfilerMiddleware' object has no attribute 'profiler'
backend_1      | ERROR    [2022-05-13 08:37:44,458] django.request: Internal Server Error: /api/test
backend_1      | Traceback (most recent call last):
backend_1      |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
backend_1      |     response = get_response(request)
backend_1      |   File "/usr/local/lib/python3.9/site-packages/django/utils/deprecation.py", line 119, in __call__
backend_1      |     response = self.process_response(request, response)
backend_1      |   File "/usr/local/lib/python3.9/site-packages/django_cprofile_middleware/middleware.py", line 67, in process_response
backend_1      |     self.profiler.create_stats()
backend_1      | AttributeError: 'ProfilerMiddleware' object has no attribute 'profiler'

shypard avatar May 13 '22 07:05 shypard

Dang I was hoping this had an answer but I see nothing since 2021 :cry:

johnbridstrup avatar Apr 07 '23 21:04 johnbridstrup

I was seeing this error on every request with Django 4.2.5.

The changes in pull request #23 by ahumeao solved this issue for me. I forked this repository, cloned the repo from my fork and pushed the modifications per the commit in pull request #23.

Then I installed from my fork like this: pip install -e git+https://github.com/ddrake/django-cprofile-middleware.git#egg=django-cprofile-middleware It has been working reliably for me since.

ddrake avatar Sep 28 '23 16:09 ddrake