[Sqlalchemy-tickets] Issue #3113: Warning for custom insert (MySQL) (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: theking-laptop <iss...@bi...> - 2014-07-06 11:12:02
|
New issue 3113: Warning for custom insert (MySQL) https://bitbucket.org/zzzeek/sqlalchemy/issue/3113/warning-for-custom-insert-mysql theking-laptop: I use MySQL as my database backend and I really want to use `INSERT... ON DUPLICATE KEY UPDATE` feature. This is my code: ``` @compiles(Insert, 'mysql') def suffix_insert(insert, compiler, **kw): stmt = compiler.visit_insert(insert, **kw) if 'on_duplicate_key_update_cols' in insert.kwargs: update_cols = insert.kwargs['on_duplicate_key_update_cols'] update_cols_length = len(update_cols) if update_cols_length > 0: stmt += ' ON DUPLICATE KEY UPDATE' stmt += " %s=VALUES(%s)" % (update_cols[0], update_cols[0]) for i in xrange(1, update_cols_length): stmt += ",%s=VALUES(%s)" % (update_cols[i], update_cols[i]) return stmt ``` It works perfectly when I use SqlAlchemy 0.9.1 or below. With higher version, everything is still fine, but I got warning: ``` lib/python2.7/site-packages/sqlalchemy/sql/dml.py:465: SAWarning: Can't validate argument 'on_duplicate_key_update'; can't locate any SQLAlchemy dialect named 'on' self._validate_dialect_kwargs(dialect_kw) ``` How can I workaround this problem? |