From 63d072581c62eb38d4b7f1dac3d261945f357546 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Sat, 23 Jan 2010 23:56:04 +0000 Subject: [PATCH] Made CookieStorage account for the overhead added by the underlying cookie encoding git-svn-id: http://code.djangoproject.com/svn/django/trunk@12285 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/messages/storage/cookie.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py index 1ac1afe550..412d4195fc 100644 --- a/django/contrib/messages/storage/cookie.py +++ b/django/contrib/messages/storage/cookie.py @@ -86,7 +86,12 @@ class CookieStorage(BaseStorage): unstored_messages = [] encoded_data = self._encode(messages) if self.max_cookie_size: - while encoded_data and len(encoded_data) > self.max_cookie_size: + # data is going to be stored eventually by CompatCookie, which + # adds it's own overhead, which we must account for. + def stored_length(val): + return len(CompatCookie().value_encode(val)[1]) + + while encoded_data and stored_length(encoded_data) > self.max_cookie_size: if remove_oldest: unstored_messages.append(messages.pop(0)) else: