From 71a4c2bac92fe4d30923490f37b993d938266e5d Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Fri, 16 Dec 2011 10:37:01 +0100 Subject: [PATCH] Fixed rollback on error on Zope (ticket #73) --- NEWS | 1 + ZPsycopgDA/db.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 4bb218e9..fb2e4cc8 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ What's new in psycopg 2.4.4 --------------------------- - Named DictCursor/RealDictCursor honour itersize (ticket #80). + - Fixed rollback on error on Zope (ticket #73). What's new in psycopg 2.4.3 diff --git a/ZPsycopgDA/db.py b/ZPsycopgDA/db.py index fe27931c..2d85b21d 100644 --- a/ZPsycopgDA/db.py +++ b/ZPsycopgDA/db.py @@ -47,12 +47,15 @@ class DB(TM, dbi_db.DB): self.calls = 0 self.make_mappings() - def getconn(self, create=True): + def getconn(self, init=True): + # if init is False we are trying to get hold on an already existing + # connection, so we avoid to (re)initialize it risking errors. conn = pool.getconn(self.dsn) - conn.set_isolation_level(int(self.tilevel)) - conn.set_client_encoding(self.encoding) - for tc in self.typecasts: - register_type(tc, conn) + if init: + conn.set_isolation_level(int(self.tilevel)) + conn.set_client_encoding(self.encoding) + for tc in self.typecasts: + register_type(tc, conn) return conn def putconn(self, close=False):