Skip to content

Commit

Permalink
fix: Fix device service update failed when startup
Browse files Browse the repository at this point in the history
Assign the id to nil in UpdateDTO before sending out the request to prevent json decode error.

Close #987

Signed-off-by: weichou <weichou1229@gmail.com>
  • Loading branch information
weichou1229 committed Jun 25, 2021
1 parent 5b9873f commit 5669c30
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/service/manageddevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (s *DeviceService) UpdateDevice(device models.Device) error {

s.LoggingClient.Debugf("Updating managed Device %s", device.Name)
req := requests.NewUpdateDeviceRequest(dtos.FromDeviceModelToUpdateDTO(device))
req.Device.Id = nil
ctx := context.WithValue(context.Background(), common.CorrelationHeader, uuid.NewString())
_, err := s.edgexClients.DeviceClient.Update(ctx, []requests.UpdateDeviceRequest{req})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/service/managedwatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s *DeviceService) UpdateProvisionWatcher(watcher models.ProvisionWatcher)

s.LoggingClient.Debugf("Updating managed ProvisionWatcher: %s", watcher.Name)
req := requests.NewUpdateProvisionWatcherRequest(dtos.FromProvisionWatcherModelToUpdateDTO(watcher))
req.ProvisionWatcher.Id = nil
ctx := context.WithValue(context.Background(), common.CorrelationHeader, uuid.NewString())
_, err := s.edgexClients.ProvisionWatcherClient.Update(ctx, []requests.UpdateProvisionWatcherRequest{req})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (s *DeviceService) selfRegister() errors.EdgeX {
} else {
s.LoggingClient.Infof("device service %s exists, updating it", s.ServiceName)
req := requests.NewUpdateDeviceServiceRequest(dtos.FromDeviceServiceModelToUpdateDTO(localDeviceService))
req.Service.Id = nil
_, err = s.edgexClients.DeviceServiceClient.Update(ctx, []requests.UpdateDeviceServiceRequest{req})
if err != nil {
s.LoggingClient.Errorf("failed to update device service %s with local config: %v", localDeviceService.Name, err)
Expand Down

0 comments on commit 5669c30

Please sign in to comment.