The query was a unicode string, which was causing the comparison on line 54 to fail (apparently a comparison is always false if it can't convert the string properly).