Flask-SQLAlchemy: How to conditionally insert or update a row,db.session.commit()