django-simple-history icon indicating copy to clipboard operation
django-simple-history copied to clipboard

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

Open LoFenk opened this issue 1 year ago • 5 comments

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 (so I'm posting it in both) . Either work fine independently but not together so there seems to be a conflict somewhere.

To reproduce the bug, install both apps, and then use 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'

LoFenk avatar Nov 13 '23 16:11 LoFenk

We encountered the same error this week. We use Wagtail 5.2 and django-simple-history in a project. After upgrading to django-simple-history 3.4.0 we encountered this error when attempting to preview a Wagtail page while editing the page. We do not encounter this error if we revert to django-simple-history 3.3.0.

rjschave avatar Nov 14 '23 20:11 rjschave

I'm seeing the same issue here. Works fine with 3.3.* but fails as described with 3.4.0.

alejandro-perez avatar Nov 27 '23 08:11 alejandro-perez

Previously the middleware made this check before deleting the request property from context, but with the refactor done in 3.4.0 it's gone

        if hasattr(HistoricalRecords.context, "request"):
            del HistoricalRecords.context.request

djowett avatar Jan 10 '24 07:01 djowett

Hi, I'm the maintainer of Django Check SEO.

I tried to re-add the if hasattr ... condition in the middleware of django-simple-history, and I can confirm that it solves the problem encountered with django-check-seo.

corentinbettiol avatar Jan 25 '24 13:01 corentinbettiol

Looks like @Tenzer and @ddabble fixed this in the master branch ~5 months ago. Can we get a new point release issued to fix this for those affected (includes me)?

andrew-cybsafe avatar Feb 02 '24 08:02 andrew-cybsafe

Closed by #1256

ddabble avatar Jul 24 '24 19:07 ddabble