Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-go] Support repeated Any fields #1864

Open
yuandrew opened this issue Mar 12, 2025 · 1 comment
Open

[api-go] Support repeated Any fields #1864

yuandrew opened this issue Mar 12, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@yuandrew
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Today our Payload visitor will visit Any fields, but we don't properly visit and parse through a map of Any's, i.e. this repeated Any field in our API.

Describe the solution you'd like
This test should pass.

func TestVisitPayloads_ArrayAny(t *testing.T) {
	msg, err := anypb.New(&update.Request{Input: &update.Input{Args: &common.Payloads{
		Payloads: []*common.Payload{{Data: []byte("orig-val")}},
	}}})
	require.NoError(t, err)
	root := &errordetails.MultiOperationExecutionFailure_OperationStatus{Details: []*anypb.Any{msg}}
	var anyCount int
	err = VisitPayloads(context.Background(), root, VisitPayloadsOptions{
		Visitor: func(ctx *VisitPayloadsContext, p []*common.Payload) ([]*common.Payload, error) {
			anyCount++
			// Only mutate if the payloads has "test"
			if len(p) == 1 && string(p[0].Data) == "orig-val" {
				return []*common.Payload{{Data: []byte("new-val")}}, nil
			}
			return p, nil
		},
	})
	require.NoError(t, err)
	require.Equal(t, 1, anyCount)
	update1, err := root.Details[0].UnmarshalNew()

	require.NoError(t, err)
	require.Equal(t, "new-val", string(update1.(*update.Request).Input.Args.Payloads[0].Data))
}

Likely will require enhancing or creating a new case here https://github.com/temporalio/api-go/blob/4c00816d0d87af129f51a33be6f3b2ca20e3ccb7/cmd/proxygenerator/interceptor.go#L262

Additional context
Add any other context or screenshots about the feature request here.

@yuandrew yuandrew added the enhancement New feature or request label Mar 12, 2025
@yuandrew
Copy link
Contributor Author

When this is implemented, this is another test that could be added

func TestOperationStatus(t *testing.T) {
	require := require.New(t)

	var messageType protoreflect.MessageType
	protoregistry.GlobalTypes.RangeMessages(func(mt protoreflect.MessageType) bool {
		if string(mt.Descriptor().FullName()) == "temporal.api.errordetails.v1.MultiOperationExecutionFailure.OperationStatus" { 
			messageType = mt
		}
		return true
	})

	// Create empty instance and populate with test values
	msg := messageType.New().Interface().(proto.Message)
	var totalCount, count int
	populatePayload(&msg, msg, require, &totalCount, &count)

	require.Equal(0, count)
	require.Equal(1, totalCount)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant