Skip to content

[DEPR]: CountryMiddleware (openedx.core.djangoapps.geoinfo.middleware) #575

Open

Description

@blarghmatey

RFC Start Date

Target Plan Accepted Date

<RFC Start Date + 2 weeks>

Target Transition Unblocked Date

The date openedx/openedx-platform#39111 merges. From that commit on, CountryMiddleware does nothing and can be removed from MIDDLEWARE with no change in behavior.

Earliest Breaking Changes Unblocked Date

<RFC Start Date + 6 months>

Earliest Open edX Named Release with Breaking Changes

The first named release after the one that ships #39111. If #39111 merges before the Willow cut, Willow carries the shim and the release after Willow drops it.

Rationale

CountryMiddleware wrote country_code and ip_address into the session on every request from a client without a session cookie, so each such response created a new session and carried a Set-Cookie. That includes responses with no other use for a session, such as course assets served by contentserver. #39111 replaces it with geoinfo.api.country_code_for_request, which looks the country up per request and never touches the session.

Deleting the module outright makes any deployment that still lists it in MIDDLEWARE fail at startup with ModuleNotFoundError, so #39111 keeps it for one release as a no-op shim. This ticket tracks removing that shim.

Removal

openedx.core.djangoapps.geoinfo.middleware.CountryMiddleware (openedx/core/djangoapps/geoinfo/middleware.py) and its tests in openedx/core/djangoapps/geoinfo/tests/test_middleware.py.

Replacement

openedx.core.djangoapps.geoinfo.api.country_code_for_request(request), added in #39111. The two in-tree readers of the session value (lms/djangoapps/courseware/block_render.py and openedx/core/djangoapps/catalog/utils.py) already call it. Code outside the platform that reads request.session['country_code'] should call it instead.

Deprecation

In #39111 the shim raises MiddlewareNotUsed, so Django drops it from the middleware chain at startup. It also emits a DeprecationWarning and logs a warning naming the setting to remove.

Additional Info

No database or data migration. Stale country_code/ip_address keys in existing sessions are ignored and expire with the session.

decorator_from_middleware(CountryMiddleware) stopped working as of #39111, because the shim raises at construction. There is no in-tree use of it.

Transition Unblocked Tasks

Feature Removal Tasks

  • Remove openedx/core/djangoapps/geoinfo/middleware.py and openedx/core/djangoapps/geoinfo/tests/test_middleware.py
  • Note the removal in the release notes for the named release above

Metadata

Metadata

Assignees

No one assigned

    Labels

    deprProposal for deprecation & removal per OEP-21

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions