Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LoFenk opened this issue Nov 13, 2023 · 5 comments

Comments

@LoFenk
Copy link

LoFenk commented Nov 13, 2023

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'
@rjschave
Copy link

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.

@alejandro-perez
Copy link

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

@djowett
Copy link

djowett commented Jan 10, 2024

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

@corentinbettiol
Copy link

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.

@andrew-cybsafe
Copy link

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants