a 6 hour evil nightmare of hell caused by sqlalchemy trying to be clever