def update_roles(cls, instance, roles): """Update existing Release instance with specified roles. Previous ones are deleted. IMPORTANT NOTE: attempting to remove roles that are already assigned to nodes will lead to an Exception. :param instance: Release instance :param roles: list of new roles names :returns: None """ db().query(models.Role).filter( not_(models.Role.name.in_(roles)) ).filter( models.Role.release_id == instance.id ).delete(synchronize_session='fetch') db().refresh(instance) added_roles = instance.roles for role in roles: if role not in added_roles: new_role = models.Role( name=role, release=instance ) db().add(new_role) added_roles.append(role) db().flush()
def handler_sample(): try: db().add(models.Role()) db().flush() except exc.IntegrityError: db().rollback() raise
def handler_sample(): db().add(models.Role()) raise web.HTTPError(400)
def handler_sample(): db().add(models.Role()) db().flush() raise errors.DumpError()
def handler_sample(): try: db().add(models.Role()) db().flush() except exc.IntegrityError: db().commit()