refactor sqlalchemy 9.x patch