try:
    transaction.commit()
except IntegrityError:
    transaction.abort()
session = DBSession()
session.add(my_model)
SQLAlchemy: Re-saving model's unique field after trying to save non-unique value