Skip to content

Fix workflow list MongoDB fallback#1608

Open
JoshVanL wants to merge 2 commits intodapr:masterfrom
JoshVanL:mongodb-wf-list-fix
Open

Fix workflow list MongoDB fallback#1608
JoshVanL wants to merge 2 commits intodapr:masterfrom
JoshVanL:mongodb-wf-list-fix

Conversation

@JoshVanL
Copy link
Contributor

The CLI's direct MongoDB fallback (used when gRPC ListInstanceIDs is unavailable) searched for a "key" field, but the Dapr MongoDB state store stores document keys in the "_id" field. This caused dapr workflow list -c 'mongodb://...' to always return empty results.

The CLI's direct MongoDB fallback (used when gRPC ListInstanceIDs is
unavailable) searched for a "key" field, but the Dapr MongoDB state
store stores document keys in the "_id" field. This caused
`dapr workflow list -c 'mongodb://...'` to always return empty results.

Signed-off-by: joshvanl <me@joshvanl.dev>
Copilot AI review requested due to automatic review settings March 13, 2026 00:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the CLI’s MongoDB direct-query fallback used for dapr workflow list by querying workflow metadata keys from MongoDB’s _id field (as stored by the Dapr MongoDB state store), instead of a non-existent key field.

Changes:

  • Update MongoDB filter to query on _id and decode keys from _id.
  • Adjust MongoDB projection to return _id.
  • Add unit tests validating _id-based behavior and the generated query filter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/workflow/db/mongo.go Switches MongoDB list query from key to _id and updates projection/decoding accordingly.
pkg/workflow/db/mongo_test.go Adds mocked MongoDB tests for listing and filter construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +38 to +43
keys, err := ListMongo(mt.Context(), mt.DB, "daprCollection", ListOptions{
Namespace: "default",
AppID: "myapp",
})
require.NoError(t, err)
assert.Equal(t, []string{key1, key2}, keys)
Comment on lines +57 to +75
mt.Run("filter uses _id field with correct regex", func(mt *mtest.T) {
mt.AddMockResponses(mtest.CreateCursorResponse(0, "daprStore.daprCollection", mtest.FirstBatch))

_, err := ListMongo(mt.Context(), mt.DB, "daprCollection", ListOptions{
Namespace: "default",
AppID: "myapp",
})
require.NoError(t, err)

// Verify the find command was sent with _id filter.
cmd := mt.GetStartedEvent().Command
filterVal := cmd.Lookup("filter")
filterDoc := filterVal.Document()

// The filter should contain an "_id" field, not "key".
_, err = filterDoc.LookupErr("_id")
assert.NoError(t, err, "filter should query on _id field")
_, err = filterDoc.LookupErr("key")
assert.Error(t, err, "filter should not query on key field")
Signed-off-by: joshvanl <me@joshvanl.dev>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the CLI’s MongoDB direct-access fallback for workflow listing by querying the correct MongoDB document key field (_id) used by the Dapr MongoDB state store, preventing empty results when gRPC ListInstanceIDs is unavailable.

Changes:

  • Update MongoDB list query to filter/project on _id rather than key.
  • Decode _id values into the returned key list.
  • Add unit tests validating _id usage, regex filter construction, and empty-result behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pkg/workflow/db/mongo.go Switches Mongo query filter/projection and decode tag from key to _id.
pkg/workflow/db/mongo_test.go Adds mock-based tests ensuring _id is used and regex is formed correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +32 to +36
mt.AddMockResponses(mtest.CreateCursorResponse(1, "daprStore.daprCollection", mtest.FirstBatch,
bson.D{{Key: "_id", Value: key1}},
), mtest.CreateCursorResponse(0, "daprStore.daprCollection", mtest.NextBatch,
bson.D{{Key: "_id", Value: key2}},
))
Comment on lines +47 to +48
mt.AddMockResponses(mtest.CreateCursorResponse(0, "daprStore.daprCollection", mtest.FirstBatch))

Comment on lines +58 to +59
mt.AddMockResponses(mtest.CreateCursorResponse(0, "daprStore.daprCollection", mtest.FirstBatch))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants