Comment 7 for bug 865859

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) wrote :

@Dillon

I've a similar problem with one of the test cases (mentioned in note #4) and found a fix. It seems that for Python 3, it's good to have __del__ and call close(). I'm not sure it will help you, but please can you patch and see if it works for you?
The change goes in MySQLConnection:

class MySQLConnection(object):

  def __del__(self):
      self.close()

Test case involves assigning a new connection to a connection still in use, which did not commit changes for example:

    cnx = mysql.connector.connection.MySQLConnection(**config)
    cur = cnx.cursor()
    cur.execute("DROP TABLE IF EXISTS t1")
    cur.execute("CREATE TABLE t1 (c1 INT)")
    cur.execute("INSERT INTO t1 (c1) VALUES (1)")
    cnx = mysql.connector.connection.MySQLConnection(**config)
    cur = cnx.cursor()
    cur.execute("DROP TABLE IF EXISTS t1")

I'm adding a explicit __del__-destructor to Python 2 code as well.