Skip to content

Commit e7d3cb7

Browse files
committed
A bug caused by psycopg2 recently added a new boolean not callable autocommit attribute was fixed.
git-svn-id: http://svn.colorstudy.com/SQLObject/trunk@4428 95a46c32-92d2-0310-94a5-8d71aeb3d4b3
1 parent db23a55 commit e7d3cb7

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

docs/News.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ SQLObject (trunk)
1313
Features & Interface
1414
--------------------
1515

16+
* A bug caused by psycopg2 recently added a new boolean not callable
17+
autocommit attribute was fixed.
18+
1619
SQLObject 1.1.1
1720
===============
1821

sqlobject/postgres/pgconnection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ def _connectionFromParams(cls, user, password, host, port, path, args):
118118
def _setAutoCommit(self, conn, auto):
119119
# psycopg2 does not have an autocommit method.
120120
if hasattr(conn, 'autocommit'):
121-
conn.autocommit(auto)
121+
try:
122+
conn.autocommit(auto)
123+
except TypeError:
124+
conn.autocommit = auto
122125

123126
def makeConnection(self):
124127
try:
@@ -128,10 +131,7 @@ def makeConnection(self):
128131
conn = self.module.connect(**self.dsn_dict)
129132
except self.module.OperationalError, e:
130133
raise self.module.OperationalError("%s; used connection string %r" % (e, self.dsn))
131-
if self.autoCommit:
132-
# psycopg2 does not have an autocommit method.
133-
if hasattr(conn, 'autocommit'):
134-
conn.autocommit(1)
134+
if self.autoCommit: self._setAutoCommit(conn, 1)
135135
c = conn.cursor()
136136
if self.schema:
137137
c.execute("SET search_path TO " + self.schema)

0 commit comments

Comments
 (0)