Opened 11 years ago

Closed 11 years ago

Last modified 5 years ago

#22426 closed Bug (fixed)

Django >= 1.6.0 can't handle old style messages cookie

Reported by: iivvoo Owned by: ofirov
Component: contrib.messages Version: 1.6
Severity: Release blocker Keywords: messages, cookie, 1.4
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The message cookie format has changed in Django 1.5.x, Django 1.6.x no longer supports the old format.

If you upgrade your project from Django 1.4.x directly to 1.6.x (skipping the 1.5 release), your application will fail quickly on old-style message cookies:

 Exception Type: IndexError
 Exception Value:
 list index out of range
 Exception Location: (...) django/contrib/messages/storage/cookie.py in process_messages, line 37

Django 1.5 contained some backward compatibility to handle both styles:

https://github.com/django/django/commit/9e7183073f64e541587e8dcfd8bb3ddeb47f8162

but this code is no longer present in Django 1.6.2

Since you can't ask all your users to delete their cookies if they run into this error, there's no easy/quick workaround.

It's not uncommon for projects to skip a version. Also, Django 1.4.x is LTS and people may jump from LTS release to LTS release, which means they will also run into this issue.

Change History (7)

comment:1 by iivvoo, 11 years ago

FWIW I've created a small piece of middleware as a workaround: http://vanderwijk.info/blog/workaround-django-1-4-django-1-6-message-cookie-error

but the real fix is to simply restore the backward compatibility from Django 1.5

comment:2 by Florian Apolloner, 11 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Version: 1.6master

Since the backwards compat code is only 2 lines, I'd leave it in there at least till the next LTS. Needs backport to 1.6+

comment:3 by ofirov, 11 years ago

Has patch: set
Owner: changed from nobody to ofirov
Status: newassigned
Version: master1.6

I just sent a pull request for a fix for this:
https://github.com/django/django/pull/2559

I added it to 1.6 and left it out of master.

comment:4 by Florian Apolloner <florian@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In f286721f7fdc2202f77a5f4d650d9d0779b86811:

Fixed #22426 -- Added support old-style d.c.messages format.

Forward ported code from 1.5 that adds backwards compatibility with legacy message length.
See commit 9e7183073f64e541587e8dcfd8bb3ddeb47f8162 for details.

Thanks to Ofir Ovadia for the initial patch.

comment:5 by Florian Apolloner <florian@…>, 11 years ago

In 97b5833e212d3e6520dfa43525aa75f625a760a0:

[1.7.x] Fixed #22426 -- Added support old-style d.c.messages format.

Forward ported code from 1.5 that adds backwards compatibility with legacy message length.
See commit 9e7183073f64e541587e8dcfd8bb3ddeb47f8162 for details.

Thanks to Ofir Ovadia for the initial patch.

Backport of f286721f7fdc2202f77a5f4d650d9d0779b86811 from master.

comment:6 by Florian Apolloner <florian@…>, 11 years ago

In 6ec346ba7b251a9bcebcd467dde72463197ad210:

[1.6.x] Fixed #22426 -- Added support old-style d.c.messages format.

Forward ported code from 1.5 that adds backwards compatibility with legacy message length.
See commit 9e7183073f64e541587e8dcfd8bb3ddeb47f8162 for details.

Thanks to Ofir Ovadia for the initial patch.

Backport of f286721f7fdc2202f77a5f4d650d9d0779b86811 from master

comment:7 by GitHub <noreply@…>, 5 years ago

In e7d62e97:

Refs #22426 -- Removed pre-Django 1.5 messages compatibility code and test.

This reverts commit f286721f7fdc2202f77a5f4d650d9d0779b86811.

Note: See TracTickets for help on using tickets.
Back to Top