Skip to content

Commit

Permalink
Stop pg8000 from producing NOT IN TRANSACTION warnings
Browse files Browse the repository at this point in the history
It does behave differently than psycopg2/cffi.
  • Loading branch information
jamadden committed Jul 1, 2016
1 parent 2c3f0ba commit d94b841
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions relstorage/adapters/_postgresql_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ def __del__(self):
print("Failed to close", self, self.__type, " from:", self.__at, file=sys.stderr)
print("Deleted at", ''.join(traceback.format_stack()))

class _DoesNotRollbackIfNotInTransaction(pg8000.Connection):
# pg8000, unlike psycopg2/cffi, will actually send a ROLLBACK
# statement even if it's not in a transaction. This generates
# warnings from the server "NOT IN TRANSACTION", which are annoying
# (because we rolback() after every commit)
# So this subclass doesn't do that.

def rollback(self):
if not self.in_transaction:
return
return super(_DoesNotRollbackIfNotInTransaction,self).rollback()

@implementer(IDBDriver)
class PG8000Driver(object):
__name__ = 'pg8000'
Expand All @@ -162,6 +174,8 @@ def connect(self, dsn):
key = 'database'
kwds[key] = value
conn = self._connect(**kwds)
assert conn.__class__ is _DoesNotRollbackIfNotInTransaction.__base__
conn.__class__ = _DoesNotRollbackIfNotInTransaction
return _ConnWrapper(conn) if self._wrap else conn

ISOLATION_LEVEL_READ_COMMITTED = 'ISOLATION LEVEL READ COMMITTED'
Expand Down

0 comments on commit d94b841

Please sign in to comment.