uber-go / cadence-client

Framework for authoring workflows and activities running on top of the Cadence orchestration engine.
https://cadenceworkflow.io
MIT License
339 stars 128 forks source link

ExecuteActivity/ExecuteWorkflow not passing the input arguments correctly if the argument is nested struct with pointers #1339

Closed sruthicp closed 1 month ago

sruthicp commented 1 month ago

I'm facing an issue with Cadence where the arguments passed to an activity seem to lose their values. Specifically, the args.AuditEntry.Resource.ID inside TaskOpActivity is empty, even though it has the correct value in TaskActivity.

Here is the relevant code:

    import go.uber.org/cadence/workflow

func (t *TaskManager) TaskActivity(wfctx workflow.Context, args *taskrepo.CompleteTaskArgs) {
    logger := tracelogging.LoggerFromWorkflowContext(wfctx)

    wfctx = workflow.WithActivityOptions(wfctx, cadenceconfig.ShortCloudServicesActivityOptions())
    logger.Infof("TaskActivity args : %+v", args)
    logger.Infof("TaskActivity audit entry resource : %+v", *args.AuditEntry.Resource.ID)
    err := workflow.ExecuteActivity(wfctx, t.TaskOpActivity, args).Get(wfctx, nil)

}

func (t *TaskManager) TaskOpActivity(ctx context.Context, args *taskrepo.CompleteTaskArgs) error {
    logger := tracelogging.LoggerFromActivityContext(ctx)
    logger.Infof("TaskOpActivity args : %+v", args)
    logger.Infof("TaskOpActivity audit resource : %+v", *args.AuditEntry.Resource.ID)
    t.CompleteTask(ctx, args)

    return nil
}

The log output is as follows

    2024-05-28T10:15:30.241Z        INFO    taskmanager/task_manager_activities.go:49       TaskActivity audit entry : &{
Task:6f51ef6f-40e7-4e3a-952b-89df579066ea
User:8922afa6723011ebbe01ca32d32b6b77
LogMessages:[task completed]
AuditEntry:0xc001196fc0
OperationName:Create
ResourceID:87218358-8941-53a1-9996-e7b1e0639042}

2024-05-28T10:15:30.280Z        INFO    taskmanager/task_manager_activities.go:59       TaskOpActivity audit entry : &{
Task:6f51ef6f-40e7-4e3a-952b-89df579066ea
User:8922afa6723011ebbe01ca32d32b6b77
LogMessages:[task completed]
AuditEntry:0xc001197e60
OperationName:Create
ResourceID:87218358-8941-53a1-9996-e7b1e0639042
}

As you can see the AuditEntry object is different in TaskActivity and TaskOpActivity logs. These objects only differ in the value of args.AuditEntry.Resource.ID. TaskActivity has proper value for args.AuditEntry.Resource.ID and TaskOpActivity has no value for Resource.ID.

for more reference, providing the struct definition:

type CompleteTaskArgs struct {
    Task           entities.TaskReference
    User           entities.User
    LogMessages    []entities.PresentableString
    AuditEntry     *TaskAuditEntry
    OperationName  string
    ResourceID     string
}

type TaskAuditEntry struct {
    Resource   *entities.ResourceReference
    Permission entities.Permission
    AuditCode  entities.AuditCode
}

type ResourceReference struct {
    marshalableResourceReference
}

type marshalableResourceReference struct {
    ID   ResourceID
    Type ResourceType
    Name ResourceName
}

Why are the values of args.AuditEntry.Resource.ID not retained between TaskActivity and TaskOpActivity ?

Thanks