fanout / django-eventstream

Server-Sent Events for Django
MIT License
638 stars 84 forks source link

AttributeError: 'ASGIRequest' object has no attribute 'grip' #136

Closed JoaoSaramago closed 4 months ago

JoaoSaramago commented 4 months ago

When using 5.0.0 version with Django 5.0.2 I am getting this error:

Internal Server Error: /api/stream/cdss/notifications/counter/
Traceback (most recent call last):
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/asgiref/sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/asgiref/sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/asgiref/sync.py", line 479, in __call__
    ret: _R = await loop.run_in_executor(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/asgiref/current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/asgiref/sync.py", line 538, in thread_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/joaosaramago/PycharmProjects/platform/venv311/lib/python3.11/site-packages/django_eventstream/views.py", line 265, in events
    if not response and request.grip.proxied:
                        ^^^^^^^^^^^^
AttributeError: 'ASGIRequest' object has no attribute 'grip'
HTTP GET /api/stream/cdss/notifications/counter/ 500 [0.15, 127.0.0.1:64100]

I believe this is an issue in the line django_eventstream/views.py:265 should be:

if not response and hasattr(request, 'grip') and request.grip.proxied:

If I am mistaken what could be the problem happening here? I migrated the code from the previous version and removed channels library as it is no longer needed.

jkarneges commented 4 months ago

Thanks for the report. I'd updated the docs to not require the grip middleware but forgot to actually update the code. This is now fixed.