I know that pylons.database is about to be deprecated, but I've run
across a bug (Im using 0.9.6.1). I'm posting this as a heads up for
anyone else that may run into this. (I've also posted something in
the pylons trac http://pylonshq.com/project/pylonshq/ticket/327)
If you:
1) use the AutoConnectHub in pylons.database
2) use AutoConnectHub's inherited `doInTransaction` method
3) do not set processConnection on the AutoConnectHub instance
4) do not `connect` to the database via getConnection
then, doInTransaction will blow up. doInTransaction blows up, looking
for a threadingLocal.connection, which does not exist yet because
getConnection has not been called on the hub.
The code below illustrates this. (Change pathing of the database_uri
variable!) First, run the code with --create-table as the command
line argument. That creates the table.
Next, run the script again with the --do-in-transaction command line
argument. This should blow up.
## BEGIN TEST CODE
from pylons.database import AutoConnectHub
import sys
import sqlobject
# Setup the database connection.
database_uri = 'sqlite:/c|/tmp/sqlite.dat'
__connection__ = AutoConnectHub(database_uri)
class User(sqlobject.SQLObject):
name = sqlobject.StringCol()
def main():
if '--create-table' in sys.argv:
User.createTable()
return 0
if '--do-in-transaction' in sys.argv:
print __connection__.doInTransaction(func_for_xaction)
return 0
return 0
def func_for_xaction():
print User(name = 'func for xaction')
if __name__ == "__main__":
sys.exit(main())
## END TEST CODE
The quick fix for me was to derive from AutoConnectHub (well, really
PackageHub for me) and override doInTransaction ->
class MyAutoConnectHub(AutoConnectHub):
def doInTransaction(self, func, *args, **kw):
if not hasattr(self.threadingLocal, "connection"):
self.getConnection()
return AutoConnectHub.doInTransaction(self, func, *args, **kw)
Hope this helps someone...
jw
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---