kapt-labs / django-check-seo

Django Check SEO will check the SEO aspects of your site for you, and will provide advice in case of problems. Compatible with Django & Django-CMS!
GNU General Public License v3.0
150 stars 12 forks source link

<asgiref.local.Local object at 0xffff8cab4f90> object has no attribute 'request' #59

Open LoFenk opened 8 months ago

LoFenk commented 8 months ago

I'm not sure if this is a django-check-seo issue or a django-simple-history issue. But if I enable the middleware of django-simple-history, it breaks django-check-seo. Either work fine independently but not together so there seems to be a conflict somewhere.

To reproduce the bug, install both apps, and the django-check-seo. Here's the traceback:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:9000/django-check-seo/?page=/

Django Version: 4.2.4
Python Version: 3.11.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django_bootstrap5',
 'compressor',
 'storages',
 'cities_light',
 'simple_history',
 'django_cleanup.apps.CleanupConfig',
 'django_celery_beat',
 'django_check_seo',
 'linkcheck']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'csp.middleware.CSPMiddleware',
 'simple_history.middleware.HistoryRequestMiddleware',]

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/simple_history/middleware.py", line 37, in middleware
    with _context_manager(request):
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
    ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/simple_history/middleware.py", line 16, in _context_manager
    del HistoricalRecords.context.request
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/local.py", line 120, in __delattr__
    raise AttributeError(f"{self!r} object has no attribute {key!r}")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: AttributeError at /django-check-seo/
Exception Value: <asgiref.local.Local object at 0xffff8cab4f90> object has no attribute 'request'
corentinbettiol commented 8 months ago

Hi, I'll take a look :)

corentinbettiol commented 5 months ago

Took a look, here's my conclusion.