#52 Fix to warnings.

MySQLdb
open
Andy Dustman
MySQLdb (53)
6
2012-09-19
2008-06-06
Hodgestar
No

The _warning_check method in MySQLdb/cursors.py on trunk does a couple of things wrong:

1) It tries to call self._get_db().show_warnings() which seems to have moved to self.connection._show_warnings().

2) It passed exceptions directly through to the warn(...) function as the warning message. Warn implicitly assumes that the message is a str or unicode object by using code like "%s" % message. If message is an exception, e, this results in a call to str(e) regardless of whether e.message is unicode or not -- and throws an exception if it is unicode with non-ASCII characters [1].

The attached patch fixes both issues. For issue 2) it passes unicode(e) instead of e to the warn(...) function.

[1] Technically, it causes an error if there are characters which cannot be represented in the default encoding, which is usually ASCII.

Discussion

  • Hodgestar
    Hodgestar
    2008-06-06

    Fix _warning_check(...) method.

     
    Attachments