Uninett/nav

Update all homemade middleware to be compatible with Django 4.1

Open

#2,468 opened on Aug 19, 2022

 (1 comment) (0 reactions) (0 assignees)Python (48 forks)auto 404
djangogood first issuetask

Repository metrics

Stars
 (224 stars)
PR merge metrics
 (Avg merge 18d 18h) (6 merged PRs in 30d)

Description

Django 4.1 can run asynchronously, old-style middlewares need to be adapted in order to not trigger an exception complaining that the attribute _is_coroutine is missing.

It might not be necessary to stop inheriting from MiddlewareMixin and add a __call__-method since most of Django's own middlewares still (as of 2025-10-30, main branch) inherits from MiddlewareMixin. (Exception: RemoteUserMiddleware, and there's no reason for it not to.)

See https://docs.djangoproject.com/en/4.1/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware

Contributor guide