Ticket #220 (defect)
Opened 3 years ago
Last modified 3 years ago
2.1 sqlobjecta session adaptor problems
Status: closed (wontfix)
| Reported by: | peter@tortall.net | Assigned to: | mikerobi |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.1 |
| Component: | CherryPy code | Keywords: | |
| Cc: |
--- cherrypy/lib/filter/sessionfilter/sqlobjectadaptor.py (revision 443)
+++ cherrypy/lib/filter/sessionfilter/sqlobjectadaptor.py (working copy)
@@ -60,6 +60,8 @@
def __setattr__(self, attr, value):
if attr == 'key' or attr == 'timestamp':
raise SessionImmutableError
+ elif attr == 'timeout' or attr == 'lastAccess':
+ setattr(self.__sqlObject, self.__attrSub(attr), value)
else:
object.__setattr__(self, self.__attrSub(attr), value)
@@ -117,12 +119,11 @@
def delSession(self, sessionKey):
# figure out what to catch when this doesn't work
- Session.delete(Session.q.session_key==sessionKey)
+ self.Session.delete(self.Session.q.session_key==sessionKey)
#raise SessionNotFoundError
def cleanUpOldSessions(self):
# print cleaning up sql sessions
now = time.time()
- for session in Session.select( ((now - Session.q.last_access) < Session.q.timeout) ):
- Session.delete(session.id)
+ self.Session.delete((now - self.Session.q.last_access) > self.Session.q.timeout)
Change History
07/10/05 18:16:54: Modified by peter@tortall.net
07/10/05 21:02:55: Modified by peter@tortall.net
My original sqlobjectadaptor.py patch had some problems. Here's an updated one:
--- cherrypy/lib/filter/sessionfilter/sqlobjectadaptor.py (revision 443)
+++ cherrypy/lib/filter/sessionfilter/sqlobjectadaptor.py (working copy)
@@ -60,6 +60,8 @@
def __setattr__(self, attr, value):
if attr == 'key' or attr == 'timestamp':
raise SessionImmutableError
+ elif attr == 'timeout' or attr == 'lastAccess':
+ setattr(self.__sqlObject, self.__attrSub(attr), value)
else:
object.__setattr__(self, self.__attrSub(attr), value)
@@ -117,12 +119,13 @@
def delSession(self, sessionKey):
# figure out what to catch when this doesn't work
- Session.delete(Session.q.session_key==sessionKey)
+ for session in self.Session.select(self.Session.q.session_key == sessionKey):
+ session.destroySelf()
#raise SessionNotFoundError
def cleanUpOldSessions(self):
# print cleaning up sql sessions
now = time.time()
- for session in Session.select( ((now - Session.q.last_access) < Session.q.timeout) ):
- Session.delete(session.id)
+ for session in self.Session.select((now - self.Session.q.last_access) > self.Session.q.timeout):
+ session.destroySelf()
07/10/05 22:01:04: Modified by mikerobi
- owner changed from rdelon to mikerobi.
- status changed from new to assigned.
- description changed.
The sqlobject adaptor has been very low priority, now that the sessionFilter api is frozen it should start to get more attention. It also appears that the sqlobject is not 100% thread safe, using the the adaptor will result in occasional errors.
It might be a while before the adaptor is ready for production applications, patches are welcome. For know it will raise "a warning that it is buggy"
In the meantime, If anyone knows what type of exception sqlobject raises if a delete fails please let me know.
07/10/05 22:01:54: Modified by mikerobi
the expired() function is fixed
07/15/05 13:14:51: Modified by mikerobi
- description changed.
- summary changed from 2.1 session expired() and sqlobjectadaptor to 2.1 sqlobjecta session adaptor problems.
changed the topic and deleted everything that is no longer relavent.
08/22/05 15:25:22: Modified by mikerobi
- status changed from assigned to closed.
- resolution set to wontfix.
An sqlobject adaptor requires uneccessary complexity do to convertion to and from python dictionarys. The sqlobject adaptor has been dropped. A driver based on PyDO2 will take its place. (I am not against including an sqlobject adaptor if someone else would like to contribute it, but I suggesting waiting till after I release the PyDO adaptor, so you can see how column names are handled.)


It might also be nice to include a sample sqlobject definition of how to use the sqlobject session storage type, eg:
import cherrypy from sqlobject import * class Session(SQLObject): session_key = StringCol(length=40, notNone=True) timeout = IntCol(notNone=True, default=60*60) last_access = FloatCol(default=time.time()) timestamp = FloatCol(default=time.time()) # Add other session-associated fields here sessionKeyIndex = DatabaseIndex('session_key') cherrypy.config.update({'global': {'sessionFilter.storageType': 'sqlobject', 'sessionFilter.default.tableObject': Session}})