8000 [BUG] cms middleware defeats ASGI adaptation · Issue #7985 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content
[BUG] cms middleware defeats ASGI adaptation #7985
Closed
@jbazik

Description

@jbazik

Description

Django async support adapts synchronous middleware to an asynchronous middleware stack automagically. It does that by assuming it's synchronous and testing for async. Subclassing MiddlewareMixin makes that test positive. However, some cms middleware then overrides __call__, which django does not adapt, causing it to fail.

Of the five middlewares provided, LanguageCookieMiddleware and CurrentUserMiddleware both suffer from this.

Steps to reproduce

Run django-cms on an ASGI server (uvicorn in my case).

Expected behaviour

Django async support allows non-async django-cms to run alongside async-aware apps.

Actual behaviour

Failure is immediate if LanguageCookieMiddleware is installed:

AttributeError at /
'coroutine' object has no attribute 'set_cookie'
Request Method:	GET
Request URL:	https://test-server.example.com/
Django Version:	4.2.15
Exception Type:	AttributeError
Exception Value:	
'coroutine' object has no attribute 'set_cookie'
Exception Location:	/usr/local/share/sites/csweb/lib/python3.11/site-packages/cms/middleware/language.py, line 54, in __call__
Raised during:	cms.views.details
Python Executable:	/usr/local/share/sites/csweb/bin/python
Python Version:	3.11.2

Additional information (CMS/Python/Django versions)

python 3.11.2
django 4.2.14
django-cms 3.11.6

Do you want to help fix this issue?

  • [ X] Yes, I want to help fix this issue and I will join the channel #pr-reviews on the Discord Server to confirm with the community that a PR is welcome.
  • No, I only want to report the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0