Arnar Birgisson
arnarb at oddi.is
Wed Oct 19 08:00:06 EDT 2005
Nope.. from the MySQL docs: REPLACE works exactly like INSERT, except that if an old record in the table has the same value as a new record for a PRIMARY KEY or a UNIQUE index, the old record is deleted before the new record is inserted. Since the column "sid" is my primary key, only that line gets updated. In any case, the scenariou you described should only happen if someone else's session is saved between the time I save mine and try to load it, which is not the case since I'm the only one accessing this app right now. The exact same code worked before the kernel upgrade.. thanks anyway for your response.. Arnar >>> "Dave Britton" <dave at davebritton.com> 19.10.2005 11:43 >>> Don't you need to specify a WHERE clause ("WHERE sid=%d" %self._sid) in the save update: c.execute("replace into sessiondata (sid, created, accessed, timeout, data) " + "values (%s, %s, %s, %s, %s)", (self._sid, dict['_created'], dict['_accessed'], dict['_timeout'], dumps(dict['_data']))) Otherwise you will update all records in the sessiondata table to the same sid value and other different sessions will not find themselves any more when in do_load: c.execute("select created, accessed, timeout, data from sessiondata where sid = %s", self._sid) if c.rowcount > 0: Rowcount will be 0 and you will need a new sessionid ----- Original Message ----- From: "Arnar Birgisson" <arnarb at oddi.is> To: <mod_python at modpython.org> Sent: Tuesday, October 18, 2005 8:03 AM Subject: [mod_python] Session ID not retained Hello there, I was running mod_python 3.1.3 on Apache 2.0.50 with linux kernel 2.4.31 until yesterday, and all was well. For other reasons, I needed to upgrade to kernel version 2.6.13 yesterday, and along with it I upgraded my distribution from Slackware 10.0 to Slackware-current. That entailed an upgrade from libc 2.3.2 to 2.3.5. After the upgrade, I recompiled Apache (still version 2.0.50) and compiled and installed mod_python 3.1.4. The problem now is that every request gets a new session id, even if the browser is clearly sending the pysid cookie correctly. I was and am running python 2.4.1 both before the upgrade and now. I tried uninstalling mod_python completely, and recompiling mod_python 3.1.3 again against the new libc, but that doesn't solve the problem. I am using að session class that I wrote myself (complete source below) that uses mysql as the data store, and the session info makes it way into the table, which tells me that sess.save() is working properly. The problem seems to be that the constructor (which just calls mod_python.Session.__init__) doesn't find the session id in the request object. I dumped request.headers_in and the pysid cookie is there. Any ideas on what I should try next? Arnar My session class (which worked fine before): from mod_python import apache, Session as apsess from Database import getExclusiveDB from cPickle import loads, dumps import time def sqlsession_cleanup(): db = getExclusiveDB() c = db.cursor() c.execute("delete from sessiondata where (unix_timestamp() - accessed) > timeout") c.close() db.commit() db.close() class SqlSession(apsess.BaseSession): def __init__(self, req, sid=0, secret=None, timeout=0, lock=1): apsess.BaseSession.__init__(self, req, sid=sid, secret=secret, timeout=timeout, lock=lock) def do_cleanup(self): self._req.register_cleanup(mem_cleanup) self._req.log_error("SqlSession: registered session cleanup", apache.APLOG_NOTICE) def do_load(self): db = getExclusiveDB() c = db.cursor() c.execute("select created, accessed, timeout, data from sessiondata where sid = %s", self._sid) if c.rowcount > 0: row = c.fetchone() retval = { "_data": loads(row[3]), "_created": row[0], "_accessed": row[1], "_timeout": row[2] } else: retval = None c.close() db.close() return retval def do_save(self, dict): db = getExclusiveDB() c = db.cursor() c.execute("replace into sessiondata (sid, created, accessed, timeout, data) " + "values (%s, %s, %s, %s, %s)", (self._sid, dict['_created'], dict['_accessed'], dict['_timeout'], dumps(dict['_data']))) c.close() db.commit() db.close() def do_delete(self): db = getExclusiveDB() c = db.cursor() c.execute("delete from sessiondata where sid = %s", self._sid) c.close() db.commit() db.close() _______________________________________________ Mod_python mailing list Mod_python at modpython.org http://mailman.modpython.org/mailman/listinfo/mod_python
|