From a156ba98e61b94dfb6450686a20f9012b5259772 Mon Sep 17 00:00:00 2001 From: Jonty Wareing Date: Tue, 2 Jul 2013 18:34:42 +0000 Subject: [PATCH] Correctly invalidate connections on failure _cursor does not check if the connection is still valid, meaning that once a connection has been marked as invalid it will attempt to get an sqlalchemy cursor on a broken connection and throw an exception. This commit causes the connection to be validated when using the cursor, triggering a new connection to be fetched from the pool if the previous one has been marked as dead. --- django_postgrespool/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_postgrespool/base.py b/django_postgrespool/base.py index d78966a..37761da 100644 --- a/django_postgrespool/base.py +++ b/django_postgrespool/base.py @@ -108,7 +108,7 @@ class DatabaseWrapper(Psycopg2DatabaseWrapper): self.creation = DatabaseCreation(self) def _cursor(self): - if self.connection is None: + if self.connection is None or self.connection.is_valid == False: self.connection = db_pool.connect(**self._get_conn_params()) self.connection.set_client_encoding('UTF8') tz = 'UTC' if settings.USE_TZ else self.settings_dict.get('TIME_ZONE')