Fix SQLAlchemy brain damage in get_next_job()