From 1b1fb03626475a0e32998e108a6f974b567cd2c4 Mon Sep 17 00:00:00 2001 From: kid143 Date: Thu, 25 Dec 2014 11:26:56 +0800 Subject: [PATCH] Fix bugs: 1. fix pool not working. 2. fix autocommit setting not working in SQLAlchemy proxied connection. --- django_postgrespool/base.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/django_postgrespool/base.py b/django_postgrespool/base.py index 080d20e..f06f8ee 100644 --- a/django_postgrespool/base.py +++ b/django_postgrespool/base.py @@ -95,3 +95,20 @@ def _dispose(self): else: pool.dispose() del db_pool.pools[key] + + def get_new_connection(self, conn_params): + # get new connection through pool, not creating a new one outside. + connection = db_pool.connect(**conn_params) + return connection + + def _set_autocommit(self, autocommit): + # fix autocommit setting not working in proxied connection + with self.wrap_database_errors: + if self.psycopg2_version >= (2, 4, 2): + self.connection.connection.autocommit = autocommit + else: + if autocommit: + level = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT + else: + level = self.isolation_level + self.connection.connection.set_isolation_level(level)