Skip to content

Upgrade django 5.2#437

Merged
annagav merged 17 commits intomainfrom
ag/upgrade_django
Apr 28, 2026
Merged

Upgrade django 5.2#437
annagav merged 17 commits intomainfrom
ag/upgrade_django

Conversation

@annagav
Copy link
Copy Markdown
Contributor

@annagav annagav commented Apr 15, 2026

What are the relevant tickets?

Fix https://github.com/mitodl/hq/issues/10366

Description (What does it do?)

update the default django version to 5.2.x

How can this be tested?

All tests should pass

@annagav annagav force-pushed the ag/upgrade_django branch from faaabe1 to c171e6a Compare April 23, 2026 12:26
@annagav annagav marked this pull request as ready for review April 23, 2026 14:00
Comment on lines +28 to +29
if settings.MITOL_APIGATEWAY_DISABLE_MIDDLEWARE:
return self.get_response(request)
return
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The process_response method sets a next cookie even when MITOL_APIGATEWAY_DISABLE_MIDDLEWARE is True because it lacks a check for this setting.
Severity: MEDIUM

Suggested Fix

Add a check at the beginning of the process_response method to see if settings.MITOL_APIGATEWAY_DISABLE_MIDDLEWARE is True. If it is, the method should return the response object immediately without any modifications.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/apigateway/mitol/apigateway/middleware.py#L28-L29

Potential issue: When `MITOL_APIGATEWAY_DISABLE_MIDDLEWARE` is set to `True`, the
`process_request` method correctly returns `None`. However, the newly introduced
`process_response` method is still invoked by Django's `MiddlewareMixin`. This new
method sets a `next` cookie on the response if a `next` query parameter is present in
the request, but it does not check if the middleware is disabled. Consequently, even
with the middleware disabled, any request containing a `?next=` parameter will have a
`next` cookie set, which is unintended behavior.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment thread src/apigateway/mitol/apigateway/views.py Outdated
@annagav annagav force-pushed the ag/upgrade_django branch from 05e03ab to f11f279 Compare April 23, 2026 17:26
Copy link
Copy Markdown
Collaborator

@rhysyngsun rhysyngsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/pasting this comment from slack:

Prior to 5.2 they were subclassing MiddlewareMixin (link) which gives the process_request and process_response methods, but in 5.2 they rewrote it to not subclass that but still kept the process_request but instead call it directly themselves from RemoteUserMiddleware  here. But process_response appears not to be called. So I think what you want to do it refactor that so that instead of overriding process_request we override call  instead.

@annagav annagav force-pushed the ag/upgrade_django branch from f6b67f6 to 117cece Compare April 24, 2026 17:13
@annagav annagav requested a review from rhysyngsun April 24, 2026 17:42
Copy link
Copy Markdown
Collaborator

@rhysyngsun rhysyngsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@annagav annagav merged commit 8085eb5 into main Apr 28, 2026
17 checks passed
@annagav annagav deleted the ag/upgrade_django branch April 28, 2026 16:03
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.

2 participants