Skip to content

Commit

Permalink
Fix error saving actor state for readonly changes (dapr#233)
Browse files Browse the repository at this point in the history
Signed-off-by: Tianpeng Wang <[email protected]>
  • Loading branch information
timonwong authored Jan 11, 2022
1 parent 40d8a4e commit d3c3384
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions actor/state/state_async_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func (d *DaprStateAsyncProvider) Apply(actorType, actorID string, changes []*Act
Value: value,
})
}

if len(operations) == 0 {
return nil
}

return d.daprClient.SaveStateTransactionally(context.Background(), actorType, actorID, operations)
}

Expand Down
29 changes: 29 additions & 0 deletions actor/state/state_async_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ func TestDaprStateAsyncProvider_Apply(t *testing.T) {
args args
wantErr bool
}{
{
name: "empty changes",
args: args{
actorType: "testActor",
actorID: "test-0",
changes: nil,
},
wantErr: false,
},
{
name: "only readonly state changes",
args: args{
actorType: "testActor",
actorID: "test-0",
changes: []*ActorStateChange{
{
stateName: "stateName1",
value: "Any",
changeKind: None,
},
{
stateName: "stateName2",
value: "Any",
changeKind: None,
},
},
},
wantErr: false,
},
// TODO: Add test cases.
}
for _, tt := range tests {
Expand Down

0 comments on commit d3c3384

Please sign in to comment.