Open GoogleCodeExporter opened 8 years ago
Hello? Anybody home? I'm hitting this same error as well. Is anybody responding
to issues in sqlalchemy-migrate any more?
Original comment by jaypi...@gmail.com
on 20 Mar 2011 at 6:30
On investigation into the sa-migrate code, I uncovered this, from
/migrate/versioning/script/sql.py:
def run(self, engine, step=None, executemany=True):
"""Runs SQL script through raw dbapi execute call"""
text = self.source()
# Don't rely on SA's autocommit here
# (SA uses .startswith to check if a commit is needed. What if script
# starts with a comment?)
conn = engine.connect()
try:
trans = conn.begin()
try:
# HACK: SQLite doesn't allow multiple statements through
# its execute() method, but it provides executescript() instead
dbapi = conn.engine.raw_connection()
if executemany and getattr(dbapi, 'executescript', None):
dbapi.executescript(text)
else:
conn.execute(text)
trans.commit()
except:
trans.rollback()
raise
finally:
conn.close()
The above is the method that runs when a SQL file is used for the
upgrade/downgrade. The reason that MySQLdb is barfing the Warning about
Commands out of sync is because the code above is supplying the connection with
a single string, instead of conn.execute()'ing each of the SQL statements in
the file.
I believe the warning can be safely ignored... it doesn't seem to be indicative
that an error actually occurred.
Alternately, the code above should probably be modified to work better with
MySQLdb, which specifically has issues executing multiple SQL queries in a
single string.
One option might be to use the python-sqlparse library and do something like
this:
import sqlparse
...
statements = sqlparse.split(text)
for statement in statements:
conn.execute(statement)
Original comment by jaypi...@gmail.com
on 20 Mar 2011 at 7:44
Hmm, seems that there actually *is* a problem that cannot be safely ignored
with the warning about Commands out of sync.
Still investigating...
Original comment by jaypi...@gmail.com
on 20 Mar 2011 at 7:51
Any progress in fixing this issue?
Original comment by eliqui...@gmail.com
on 6 Mar 2012 at 8:28
For real, I'm getting this error too, with multiple update statements.
Original comment by cc.emera...@gmail.com
on 7 Mar 2013 at 1:13
This appears to have caused "silent failures" in our recent migrations. The
migration logged the failure but did not abort and prevent further migrations
from running. This left our database in an undefined state and required manual
intervention to correct. We now think that migrations must be run only one at a
time and that close examination of the logs will tell us whether we have to
manually run the contents of the migration if SA has failed but reported
success.
To trigger this failure, we had several update statements. We worked around
this by using only a single statement for the migration.
81 -> 80...
Error closing cursor: (2014, "Commands out of sync; you can't run this command
now")
done
80 -> 79...
done
79 -> 78...
done
78 -> 77...
done
Original comment by jj...@yapta.com
on 9 Mar 2013 at 7:57
Original issue reported on code.google.com by
jeremy.g...@gmail.com
on 4 Nov 2010 at 3:50