Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who is throwing (and catching) this MySQL Exception?

i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:

Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x20108150>> ignored

I have many "try" and "exception" blocks in my code--if the exception occurred within one of those, then I would see my own debugging messages. The above Exception is obviously being caught somewhere since my program does not abort when the Exception is thrown.

I'm very puzzled, can someone help me out?

like image 308
Shlomo Shmai Avatar asked Feb 18 '10 19:02

Shlomo Shmai


People also ask

What are MySQL exceptions?

MySqlException Class. The exception that is thrown when MySQL returns an error. This class cannot be inherited. Inheritance Hierarchy. System.

How are errors returned when a query or connection fails in MySQLdb?

InterfaceError: When database connection fails for some reason, MySQLdb will raise an InterfaceError. Note InterfaceError only get raise when there is internal problem in connection to the database, MySQLdb will not raise InterfaceError because of wrong database name or password.

How does Python handle MySQL errors?

Handling Warnings By default, MySQL Connector/Python neither fetch warnings nor raise an exception on warnings. But, we can change that using the following arguments of the connect() function. If set to True warnings are fetched automatically after each query without having to manually execute SHOW WARNINGS query.


2 Answers

I had exactly that error (using MySQLdb and Django) and discovered that the reason it was "ignored" was that it occurred in a __del__ method. Exceptions in __del__ are categorically ignored: object.__del__ datamodel

There doesn't seem to be any way to catch it from further up the stack (at least according to this thread), but you can edit MySQLdb/cursors.py or monkey-patch to get your own __del__ in there that catches the exception and drops you into a pdb prompt or logs a full traceback.

like image 166
Mu Mind Avatar answered Sep 22 '22 12:09

Mu Mind


This is a Python Error.

See: http://eric.lubow.org/2009/python/pythons-mysqldb-2014-error-commands-out-of-sync/

It looks like there is a problem with your MySQLdb Query.

like image 26
Todd Moses Avatar answered Sep 21 '22 12:09

Todd Moses