Ticket #6984: load_session_before_save.diff

File load_session_before_save.diff, 2.1 KB (added by mrts, 16 years ago)

The DRY version. Note that this is backwards-incompatible for custom backends. Tested with r8187

  • django/contrib/sessions/backends/base.py

     
    217217        """
    218218        Saves the session data.
    219219        """
     220        # Avoid race conditions, see #6984. Make sure the session dict is
     221        # loaded into memory before saving it back.
     222        self._get_session()
     223        self._save()
     224
     225    def _save(self):
     226        """
     227        The actual saving function that has to be overridden by backends.
     228        """
    220229        raise NotImplementedError
    221230
    222231    def delete(self, session_key):
  • django/contrib/sessions/backends/file.py

     
    6060            pass
    6161        return session_data
    6262
    63     def save(self):
     63    def _save(self):
    6464        try:
    6565            f = open(self._key_to_file(self.session_key), "wb")
    6666            try:
  • django/contrib/sessions/backends/cache.py

     
    1313        session_data = self._cache.get(self.session_key)
    1414        return session_data or {}
    1515
    16     def save(self):
     16    def _save(self):
    1717        self._cache.set(self.session_key, self._session, self.get_expiry_age())
    1818
    1919    def exists(self, session_key):
  • django/contrib/sessions/backends/db.py

     
    3636            return False
    3737        return True
    3838
    39     def save(self):
     39    def _save(self):
    4040        Session.objects.create(
    4141            session_key = self.session_key,
    4242            session_data = self.encode(self._session),
Back to Top