temporalio / sdk-java

Temporal Java SDK
https://temporal.io
Apache License 2.0
200 stars 134 forks source link

Kotlin `ActivityStubExt.execute*` extension functions wrap arguments in list #2018

Open rgrochowicz opened 3 months ago

rgrochowicz commented 3 months ago

Expected Behavior

When I use the ActivityStubExt.execute extension function, I expect the args parameter to be given as-is to the underlying ActivityStub.execute method (keeping the varargs intact).

Actual Behavior

The varargs args parameters to ActivityStubExt.execute is wrapped in a list rather than provided as a varargs parameter to ActivityStub.execute.

Steps to Reproduce the Problem

  1. Create a new ActivityStub via Workflow.newUntypedActivityStub
  2. Import the Kotlin extension method via import io.temporal.workflow.execute
  3. Call activityStub.execute<Void>("activityName", object { val foo = 1 })
  4. Observe that the arguments were wrapped in a list rather than given directly to ActivityStub.execute

More complete example:

import io.temporal.workflow.execute
import io.temporal.activity.ActivityOptions

// ... within workflow ...

val activityStub = Workflow.newUntypedActivityStub(ActivityOptions {})
activityStub.execute("activityName", object { val foo = 1 })

The ActivityTaskScheduled event has an input of:

[
  [
    {
      "foo": 1
    }
  ]
]

Rather than:

[
  {
    "foo": 1
  }
]

The incorrect input is wrapped in an extra list.

To fix, I suspect that the call to ActivityStub.execute with varargs in ActivityStubExt.kt needs to use the spread operator (*).

Specifications

Quinn-With-Two-Ns commented 3 months ago

Yes I think we are missing a spread operator, thank you for reporting this. I will follow up with my team and consider if there are any backwards compatibility issues with fixing this.