Skip to content

Fix CookieMiddleware.set_cookie() with aware expires on Django 5.0+ - #2238

Open
youssef-elaasri wants to merge 1 commit into
django:mainfrom
youssef-elaasri:fix-aware-cookie-expires
Open

youssef-elaasri wants to merge 1 commit into
django:mainfrom
youssef-elaasri:fix-aware-cookie-expires

Conversation

@youssef-elaasri

Copy link
Copy Markdown

Fixes #2237.

CookieMiddleware.set_cookie() passed django.utils.timezone.utc to make_naive() for timezone-aware expires values. Django removed that alias in 5.0, so the call raised AttributeError on every supported Django version. This uses datetime.timezone.utc instead, which is what the alias pointed to.

Added test_set_cookie_aware_expires. It fails on main with the AttributeError and passes with the fix. pytest passes on Django 5.2 / Python 3.13, except the Selenium test test_real_time_delete_message, which fails the same way on main locally. flake8, black and isort are clean.

…o 5.0+.

django.utils.timezone.utc was removed in Django 5.0.
@youssef-elaasri

Copy link
Copy Markdown
Author

Friendly ping: is there anything I should change to get this reviewed? The CI workflows haven't run yet, I think they're waiting for approval since this is my first PR here. Happy to adjust if you'd prefer a different approach to the fix for #2237.

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.

CookieMiddleware.set_cookie crashes on Django 5 with an aware expires (timezone.utc removed)

1 participant