Ticket #18135: 18135-sleeping-mysql-connection-1.4.X.diff

File 18135-sleeping-mysql-connection-1.4.X.diff, 1.2 KB (added by Ramiro Morales, 13 years ago)

Patch for this issue in 1.4.X branch

  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    a b  
    407407
    408408    def get_server_version(self):
    409409        if not self.server_version:
     410            new_connection = False
    410411            if not self._valid_connection():
    411                 self.cursor()
    412             m = server_version_re.match(self.connection.get_server_info())
     412                # Ensure we have a connection with the DB by using a temporary
     413                # cursor
     414                new_connection = True
     415                self.cursor().close()
     416            server_info = self.connection.get_server_info()
     417            if new_connection:
     418                # Make sure we close the connection
     419                self.connection.close()
     420                self.connection = None
     421            m = server_version_re.match(server_info)
    413422            if not m:
    414                 raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
     423                raise Exception('Unable to determine MySQL version from version string %r' % server_info)
    415424            self.server_version = tuple([int(x) for x in m.groups()])
    416425        return self.server_version
    417426
Back to Top