Skip to content

Commit

Permalink
fixed problem with session __hash
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Oct 16, 2012
1 parent 6b9ebb6 commit ab95dfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Version 2.1.1 (2012-10-15 19:39:19) dev
Version 2.1.1 (2012-10-15 20:43:47) dev
18 changes: 13 additions & 5 deletions gluon/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ def connect(
rcookies = response.cookies
rcookies[response.session_id_name] = response.session_id
rcookies[response.session_id_name]['path'] = '/'
self.__hash = hashlib.md5(str(self)).digest()
pickle = cPickle.dumps(self)
self.__hash = hashlib.md5(pickle).digest()
if self.flash:
(response.flash, self.flash) = (self.flash, None)

Expand Down Expand Up @@ -653,16 +654,20 @@ def _try_store_in_db(self, request, response):

# don't save if no change to session
__hash = self.__hash
pickle = None
if __hash is not None:
del self.__hash
if __hash == hashlib.md5(str(self)).digest():
pickle = cPickle.dumps(self)
if __hash == hashlib.md5(pickle).digest():
return
else:
pickle = cPickle.dumps(self)

(record_id_name, table, record_id, unique_key) = \
response._dbtable_and_field
dd = dict(locked=False, client_ip=request.client.replace(':','.'),
modified_datetime=request.now,
session_data=cPickle.dumps(dict(self)),
session_data=pickle,
unique_key=unique_key)
if record_id:
table._db(table.id == record_id).update(**dd)
Expand All @@ -680,9 +685,11 @@ def _try_store_on_disk(self, request, response):

# don't save if no change to session
__hash = self.__hash
pickle = None
if __hash is not None:
del self.__hash
if __hash == hashlib.md5(str(self)).digest():
pickle = cPickle.dumps(self)
if __hash == hashlib.md5(pickle).digest():
self._close(response)
return

Expand All @@ -700,7 +707,8 @@ def _try_store_on_disk(self, request, response):
response.session_locked = True

if response.session_file:
cPickle.dump(dict(self), response.session_file)
if not pickle: pickle = cPickle.dumps(self)
response.session_file.write(pickle)
response.session_file.truncate()
self._close(response)

Expand Down

0 comments on commit ab95dfa

Please sign in to comment.