Skip to content

Add LocaleMiddleware to fix language chooser warning in tests#2877

Closed
njg7194 wants to merge 1 commit intopython:mainfrom
njg7194:fix/locale-middleware-warning
Closed

Add LocaleMiddleware to fix language chooser warning in tests#2877
njg7194 wants to merge 1 commit intopython:mainfrom
njg7194:fix/locale-middleware-warning

Conversation

@njg7194
Copy link
Copy Markdown

@njg7194 njg7194 commented Feb 1, 2026

Summary

This PR adds django.middleware.locale.LocaleMiddleware to the MIDDLEWARE setting to resolve the warning that appears during test runs.

Changes

  • Added LocaleMiddleware after SessionMiddleware in pydotorg/settings/base.py

Issue

Fixes #2742

Context

The admin_interface package's language chooser feature requires LocaleMiddleware to be present in the MIDDLEWARE setting. Without it, a warning is raised:

UserWarning: Language chooser requires 'django.middleware.locale.LocaleMiddleware' in your MIDDLEWARE to work.

The middleware is placed after SessionMiddleware as per Django's documentation, which recommends it be positioned early, but after SessionMiddleware.

This fixes the UserWarning about Language chooser requiring
'django.middleware.locale.LocaleMiddleware' in MIDDLEWARE.

Fixes python#2742
@njg7194 njg7194 requested a review from JacobCoffee as a code owner February 1, 2026 04:17
@JacobCoffee
Copy link
Copy Markdown
Member

hey @njg7194 thanks for the PR. don't want to discourage you but since python.org is english-only, the simpler fix is setting LANGUAGES == [[("en-us", "English")] in base settings and clean it up that way! this way would load more unnecessarily

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

Successfully merging this pull request may close these issues.

Tests: Language chooser middleware warning during tests

2 participants