Skip to content

Commit 4f35813

Browse files
Support DefaultIdentificationHydrator in cosmosdb state component (#1121)
Follow-up to #1104 to support AD Auth codepath as well. `NewConfig()` and `NewConfigWithServicePrincipal()` both set the `Config.IdentificationHydrator` to the `DefaultIdentificationHydrator` in the underlying a8m/documentdb library. That implementation ends up calling `reflect.Value.Elem.FieldByName()`, which requires that the value passed to it is an interface or pointer, otherwise the Elem() call fails to dereference which causes a panic. cosmosdb.go passes the input to `UpsertDocument` by value today, which is eventually passed to the `DefaultIdentificationHydrator`, so changing the value passed to a pointer resolves the failure. Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
1 parent a0542ec commit 4f35813

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

state/azure/cosmosdb/cosmosdb.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,9 @@ func (c *StateStore) Init(meta state.Metadata) error {
114114
// Create the client; first, try authenticating with a master key, if present
115115
var config *documentdb.Config
116116
if m.MasterKey != "" {
117-
config = &documentdb.Config{
118-
MasterKey: &documentdb.Key{
119-
Key: m.MasterKey,
120-
},
121-
}
117+
config = documentdb.NewConfig(&documentdb.Key{
118+
Key: m.MasterKey,
119+
})
122120
} else {
123121
// Fallback to using Azure AD
124122
env, errB := azure.NewEnvironmentSettings("cosmosdb", meta.Properties)
@@ -273,7 +271,7 @@ func (c *StateStore) Set(req *state.SetRequest) error {
273271
if err != nil {
274272
return err
275273
}
276-
_, err = c.client.UpsertDocument(c.collection.Self, doc, options...)
274+
_, err = c.client.UpsertDocument(c.collection.Self, &doc, options...)
277275

278276
if err != nil {
279277
if req.ETag != nil {

0 commit comments

Comments
 (0)