Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #4729 -- Restored functionality to the Session class so that po…

…pping a

value marks it as modified. This was accidentally lost in the changes in
[6333]. Thanks, __hawkeye__.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6558 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4c0d8d882d1796b08c51eb6930de1327311a0f1d 1 parent 4362d15
Malcolm Tredinnick authored October 20, 2007
1  django/contrib/sessions/backends/base.py
@@ -48,6 +48,7 @@ def get(self, key, default=None):
48 48
         return self._session.get(key, default)
49 49
 
50 50
     def pop(self, key, *args):
  51
+        self.modified = self.modified or key in self._session
51 52
         return self._session.pop(key, *args)
52 53
 
53 54
     def set_test_cookie(self):
23  django/contrib/sessions/tests.py
@@ -3,6 +3,7 @@
3 3
 >>> from django.contrib.sessions.backends.db import SessionStore as DatabaseSession
4 4
 >>> from django.contrib.sessions.backends.cache import SessionStore as CacheSession
5 5
 >>> from django.contrib.sessions.backends.file import SessionStore as FileSession
  6
+>>> from django.contrib.sessions.backends.base import SessionBase
6 7
 
7 8
 >>> db_session = DatabaseSession()
8 9
 >>> db_session.modified
@@ -52,6 +53,28 @@
52 53
 >>> cache_session.delete(cache_session.session_key)
53 54
 >>> cache_session.exists(cache_session.session_key)
54 55
 False
  56
+
  57
+>>> s = SessionBase()
  58
+>>> s._session['some key'] = 'exists' # Pre-populate the session with some data
  59
+>>> s.accessed = False   # Reset to pretend this wasn't accessed previously
  60
+
  61
+>>> s.accessed, s.modified
  62
+(False, False)
  63
+
  64
+>>> s.pop('non existant key', 'does not exist')
  65
+'does not exist'
  66
+>>> s.accessed, s.modified
  67
+(True, False)
  68
+
  69
+>>> s.accessed = False  # Reset the accessed flag
  70
+
  71
+>>> s.pop('some key')
  72
+'exists'
  73
+>>> s.accessed, s.modified
  74
+(True, True)
  75
+
  76
+>>> s.pop('some key', 'does not exist')
  77
+'does not exist'
55 78
 """
56 79
 
57 80
 if __name__ == '__main__':

0 notes on commit 4c0d8d8

Please sign in to comment.
Something went wrong with that request. Please try again.