Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProgrammingError: (2014, "Commands out of sync; you can't run this command now") #15

Closed
regner opened this issue Jul 5, 2015 · 2 comments

Comments

@regner
Copy link
Contributor

regner commented Jul 5, 2015

For some reason, and hell if I can figure it out, when attempting to populate the stored procedures thanatos is tossing the following error: ProgrammingError: (2014, "Commands out of sync; you can't run this command now")

Repro code:

>>> from thanatos.database import db_utils
>>> db_conn = db_utils.get_connection()
>>> db_utils.update_sql_stored_procs(db_conn)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\projects\evetrivia\thanatos\thanatos\database\db_utils.py", line 55, in update_sql_stored_procs
    execute_sql(sql, db_connection, fetch=None)
  File "D:\projects\evetrivia\thanatos\thanatos\database\db_utils.py", line 21, in execute_sql
    cursor.execute(sql)
  File "D:\projects\evetrivia\thanatos\env\lib\site-packages\MySQLdb\cursors.py", line 222, in execute
    if not self._defer_warnings: self._warning_check()
  File "D:\projects\evetrivia\thanatos\env\lib\site-packages\MySQLdb\cursors.py", line 112, in _warning_check
    warnings = self._get_db().show_warnings()
  File "D:\projects\evetrivia\thanatos\env\lib\site-packages\MySQLdb\connections.py", line 369, in show_warnings
    self.query("SHOW WARNINGS")
  File "D:\projects\evetrivia\thanatos\env\lib\site-packages\MySQLdb\connections.py", line 280, in query
    _mysql.connection.query(self, query)
ProgrammingError: (2014, "Commands out of sync; you can't run this command now")

Everything I can find online indicates this error is caused by trying to execute more SQL code on a cursor before closing it and getting a new one. See here: http://eric.lubow.org/2009/python/pythons-mysqldb-2014-error-commands-out-of-sync/

However thanatos is specifically closing the cursor after execution of SQL code. See: https://github.com/evetrivia/thanatos/blob/master/thanatos/database/db_utils.py#L32

The hell is this crap. :(

@regner
Copy link
Contributor Author

regner commented Jul 5, 2015

Each time the code is run 1 stored proc will be stored in the DB. So if you run it once and then check the DBs stored procs 1 will be there. If you run it a second time there will be 2. So on and so on. If you run it enough times it will complete entirely and stop throwing an error.

@regner
Copy link
Contributor Author

regner commented Jul 5, 2015

Seems this is related to dropping a procedure that does not exist. Have opened an issue with mysqlclient to see why the exception is not more accurate. Will have some thing about how to handle this in Thanatos.

regner added a commit that referenced this issue Jul 31, 2015
@regner regner closed this as completed Jul 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant