Python: Why does SQLObject not work in conn.autocommit (1)?

In my server code, there is a call to _SO_fetchAlternateID (nested in some value call) that ultimately calls makeConnection in pgconnection.py .

This call fails with conn.autocommit(1) , with an error

TypeError: 'bool' object cannot be called

Here is the SQLObject code (0.8.7):

 def makeConnection(self): try: if self.use_dsn: conn = self.module.connect(self.dsn) else: conn = self.module.connect(**self.dsn_dict) except self.module.OperationalError, e: raise self.module.OperationalError("%s; used connection string %r" % (e, self.dsn)) if self.autoCommit: # psycopg2 does not have an autocommit method. if hasattr(conn, 'autocommit'): conn.autocommit(1) return conn 

Debugging shows that conn does indeed contain a connection object, but autocommit is not a method, but instead logical (False).

self.module is the self.module module (2.4.2).

Is this a configuration problem? incompatible versions?

UPDATE:

The reason is the incompatibility problem in psycopg2-2.4.2. Looking at the source code for C, psycopg / connection.h has an integer variable, unfortunately called autocommit . Version 2-2.4 is working fine.

+4
source share
2 answers

You just noticed a mistake. Take a look at this code:

 def _setAutoCommit(self, conn, auto): # psycopg2 does not have an autocommit method. if hasattr(conn, 'autocommit'): conn.autocommit(auto) 

It is assumed that conn (type: psycopg2.connection ) may not have an autocommit property, but when it has one, it should be a function. This is not true in the context of psycopg2.connection , where psycopg2.connection.autocommit is a bool .

The same assumption is made in makeConnection , as you mentioned, and several other functions there.

This could be fixed by changing each call, for example conn.autocommit(val) , to conn.autocommit = val , which should be simple, even with sed .

+4
source

It sounds like somewhere in the code someone assigns autocommit = True to the conn object.

When the translator reaches:

  conn.autocommit(1) 

In fact, he estimates:

  True(1) 

Check the contents of self.dsn or self.dsn_dict if there is no autocommit logical key.

+1
source