Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Fix pool not working bugs and autocommit #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions django_postgrespool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)