[openstack-dev] [nova] [bug] unit tests sqlite regexp() function doesn't behave like mysql

Chris Friesen chris.friesen at windriver.com
Mon Mar 31 14:54:06 UTC 2014


I mentioned this last week in another thread but I suspect it got lost.

I recently came across a situation where the code failed when running it 
under devstack but passed the unit tests.  It turns out that the unit 
tests regexp() behaves differently than the built-in one in mysql.

Down in db/sqlalchemy/api.py we end up calling

query = query.filter(column_attr.op(db_regexp_op)('None'))

When using mysql, it looks like a regexp comparison of the string 'None' 
against a NULL field fails to match.

Since sqlite doesn't have its own regexp function we provide one in 
openstack/common/db/sqlalchemy/session.py.  In the buggy case we end up 
calling it as regexp('None', None), where the types are "unicode" and 
"NoneType".  However, we end up converting the second arg to text type 
before calling reg.search() on it, so it matches.

Having unit tests that don't behave like the real thing seems like a bad 
idea...

Chris



More information about the OpenStack-dev mailing list