Ticket #8314: session-fix.diff

File session-fix.diff, 1.8 KB (added by anonymous, 7 years ago)
  • django/contrib/sessions/backends/base.py

     
    173173        delta = expiry - datetime.now()
    174174        return delta.days * 86400 + delta.seconds
    175175
    176     def get_expiry_date(self):
     176    def get_expiry_date(self, creating=False):
    177177        """Get session the expiry date (as a datetime object)."""
    178         expiry = self.get('_session_expiry')
    179         if isinstance(expiry, datetime):
    180             return expiry
     178        if creating:
     179            expiry = None
     180        else:
     181            expiry = self.get('_session_expiry')
     182            if isinstance(expiry, datetime):
     183                return expiry
    181184        if not expiry:   # Checks both None and 0 cases
    182185            expiry = settings.SESSION_COOKIE_AGE
    183186        return datetime.now() + timedelta(seconds=expiry)
  • django/contrib/sessions/backends/db.py

     
    4747        create a *new* entry (as opposed to possibly updating an existing
    4848        entry).
    4949        """
     50        if must_create:
     51            session_data = self.encode({})
     52        else:
     53            session_data = self.encode(self._session)
    5054        obj = Session(
    5155            session_key = self.session_key,
    52             session_data = self.encode(self._session),
    53             expire_date = self.get_expiry_date()
     56            session_data = session_data,
     57            expire_date = self.get_expiry_date(creating=True)
    5458        )
    5559        sid = transaction.savepoint()
    5660        try:
Back to Top