[SQLObject] Bug? Spurious connection to postgresql
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Iwan V. <iw...@re...> - 2008-12-13 17:26:32
|
Hi there, We're experiencing what I suspect to be a nasty bug with SQLObject version 0.10.2 (and, it seems earlier) when using Postgresql. I have not tested it with later versions. Any pointers to a fix would be appreciated! Here's what happens, (I attach source below that illustrates the issue): When you call dropTable on a SQLObject class, _inside a transaction_, sqlobject creates a second connection to postgresql. This connection later deadlocks randomly with the first (which is sometimes busy inside a transaction). I can't figure out why the deadlock happens, but the second connection should never have been created to start with. If you run the code below, you'll see that createTable works correctly. This code does not illustrate the deadlock, only the extra connection. Using PDB, we've narrowed it to the following: In pgconnection.py, line: 163 if self.server_version[:3] <= "7.2": the attribute access to server_version results in a "poor mans aquisition" call to the method server_version on the Transaction's _dbConnection (a PostgresConnection). In there, on line: 304 server_version = self.queryOne("SELECT version()")[0] A query is executed on the underlying db connection. This is where the extra connection is created (the original is already in a transaction at this point). If this query is done manually on the Transaction object, instead of on its underlying connection, everything works as it should. So, it seems (from our limited understanding) that it should not have gone this far, and rather should have executed the query on the Transaction object itself. We'd be very grateful for a suggestion as to how we can fix this! Thanks - Iwan Vosloo -------------------------- The code: # The connections can be observed by running this in a window while # stepping through the code below with pdb: # # while true; do clear; ps ax | grep postgres: ; sleep 0.5; done # import sqlobject # Just make this point to your DB: connectionURI = 'postgres://rhug:rhug@localhost/rhug' conn = sqlobject.connectionForURI(connectionURI).transaction() class TestMe(sqlobject.SQLObject): pass import pdb; pdb.set_trace() TestMe.createTable(connection=conn) TestMe.dropTable(connection=conn) |