Skip to content

Commit

Permalink
fix: model instance state update to unspecified state (#206)
Browse files Browse the repository at this point in the history
Because

- gorm does not update zero value when using struct

This commit

- use map for updating unspecified (zero value) model instance state
  • Loading branch information
Phelan164 committed Dec 19, 2022
1 parent 8f98635 commit 14c87d5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ func (r *repository) UpdateModelInstance(modelInstanceUID uuid.UUID, instanceInf
if result := r.db.Model(&datamodel.ModelInstance{}).Where(map[string]interface{}{"uid": modelInstanceUID}).Updates(&instanceInfo); result.Error != nil {
return status.Errorf(codes.Internal, "Error %v", result.Error)
}
if instanceInfo.State == datamodel.ModelInstanceState(modelPB.ModelInstance_STATE_UNSPECIFIED) {
if result := r.db.Model(&datamodel.ModelInstance{}).Where(map[string]interface{}{"uid": modelInstanceUID}).Updates(map[string]interface{}{"state": instanceInfo.State}); result.Error != nil {
return status.Errorf(codes.Internal, "Error %v", result.Error)
}
}

return nil
}
Expand Down

0 comments on commit 14c87d5

Please sign in to comment.