Fixing broken code in SQLAlchemy