[openstack-dev] [heat][oslo] mysql, sqlalchemy and sql_mode

Steven Hardy shardy at redhat.com
Wed Sep 11 10:37:40 UTC 2013


Hi all,

I'm investigating some issues, where data stored to a text column in mysql
is silently truncated if it's too big.

It appears that the default configuration of mysql, and the sessions
established via sqlalchemy is to simply warn on truncation rather than
raise an error.

This seems to me to be almost never what you want, since on retrieval the
data is corrupt and bad/unexpected stuff is likely.

This AFAICT is a mysql specific issue[1], which can be resolved by setting
sql_mode to "traditional"[2,3], after which an error is raised on truncation,
allowing us to catch the error before the data is stored.

My question is, how do other projects, or oslo.db, handle this atm?

It seems we either have to make sure the DB enforces the schema/model, or
validate every single value before attempting to store, which seems like an
unreasonable burden given that the schema changes pretty regularly.

Can any mysql, sqlalchemy and oslo.db experts pitch in with opinions on
this?

Thanks!

Steve

[1] http://www.enricozini.org/2012/tips/sa-sqlmode-traditional/
[2]
http://rpbouman.blogspot.co.uk/2009/01/mysqls-sqlmode-my-suggestions.html
[3] http://dev.mysql.com/doc/refman/5.5/en/server-sql-mode.html



More information about the OpenStack-dev mailing list