Code

Ticket #5063: reconnect.diff

File reconnect.diff, 778 bytes (added by asderose@…, 6 years ago)

Corrected formatting of previous patch

Line 
1Index: django/db/backends/postgresql_psycopg2/base.py
2===================================================================
3--- django/db/backends/postgresql_psycopg2/base.py      (0.96.1)
4+++ django/db/backends/postgresql_psycopg2/base.py      (working copy)
5@@ -31,6 +31,13 @@
6     def cursor(self):
7         from django.conf import settings
8         set_tz = False
9+       
10+        # psycopg2 closes the DB connection when OperationalError is thrown
11+        # We can test for this by examining connection.closed
12+        # If true we must re-establish the connection.
13+        if self.connection and self.connection.closed:
14+            self.connection = None
15+           
16         if self.connection is None:
17             set_tz = True
18             if settings.DATABASE_NAME == '':