Ticket #15802: 15802-2.diff

File 15802-2.diff, 1.4 KB (added by Jeroen Dekkers, 13 years ago)
  • django/db/backends/postgresql_psycopg2/base.py

     
    146146        new_connection = False
    147147        set_tz = False
    148148        settings_dict = self.settings_dict
     149        if self.connection is not None:
     150            try:
     151                cursor = self.connection.cursor()
     152            except Database.Error:
     153                # It seems we lost our connection without getting a notification.
     154                # Make sure the connection is really closed and connection is set
     155                # to None. The code below will then create a new connection. See
     156                # also the above comment in close().
     157                try:
     158                    self.close()
     159                except Database.Error:
     160                    pass
    149161        if self.connection is None:
    150162            new_connection = True
    151163            set_tz = settings_dict.get('TIME_ZONE')
     
    170182            self.connection.set_client_encoding('UTF8')
    171183            self.connection.set_isolation_level(self.isolation_level)
    172184            connection_created.send(sender=self.__class__, connection=self)
    173         cursor = self.connection.cursor()
     185            cursor = self.connection.cursor()
    174186        cursor.tzinfo_factory = None
    175187        if new_connection:
    176188            if set_tz:
Back to Top