Re: [SQLObject] How to use connection hub
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2005-05-03 03:43:43
|
Eduardo Elgueta wrote: > Hi All, > > I have a common set of tables (SQLObject classes) to be shared across > Wabware applications (system users, logs, system parameters, etc). > Besides these, I have an 'abstract' SQLObject class that knows how to > log, check permissions, etc. In this module, I have no connection > object/variable. > > For every application, I have a specific set of SQLObject classes. In > this case, I've tried using the classical __connection__ variable and > setting sqlobject.sqlhub.threadConnection. > > In the application login page, I set sqlobject.sqlhub.threadConnection. > > The problem I have is it's behaving erraticaly. Sometimes I get a 'No > connection defined for this process or thread' exception. Other times, I > get a 'Table doesn't exist' exception (because the SQLObject instance is > using a wrong connection). Usually (not always) the first application > (the first to be used) works ok, and the rest have this unpredictable > behaviour. If I refresh the page (F5) it works ok, but sometimes I have > to wait a while (3 to 5 minutes). Sometimes it doesn't get it right > until I restart WebKit. Hmm... that's no good. You aren't using __connection__ together with sqlhub, are you? That could cause weirdness. It sounds very odd. Are you deleting the threadConnection in sleep()? If you can figure out what's happening, maybe I can put a test in there to help future people avoid the problem. (Like should threadConnection not allow reassignment, only deletion and fresh assignment?) Oh, wait, now I see -- you are doing it in the login page. Which means the thread that served the login page has a thread connection, but the others don't. And sometimes you hit that thread when you make a request, and sometimes you don't. You need to set the threadConnection in every awake(), and remove it in every sleep(). And actually it shouldn't use connectionFromURI, now that I think about it -- you should be keeping a single instance of the connection around. This is something you should put in your SitePage. > Is there any way to fix the connection for an application? Every webware > application is a thread or a process, or neither? What approach can I > try in my situation? You can use processConnection if all threads share a connection (i.e., you aren't using transactions). -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |