Skip to content

Commit 04855b4

Browse files
jason810496guan404ming
authored andcommitted
Keep taskDef out of Context's constructor and reuse resolveWiredAll
1 parent 06a45fa commit 04855b4

4 files changed

Lines changed: 7 additions & 16 deletions

File tree

‎java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/Context.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ data class TaskInstance(
123123
data class Context(
124124
@JvmField val dagRun: DagRun,
125125
@JvmField val ti: TaskInstance,
126-
/** Registration of the executing task; resolves wired data inputs. */
127-
internal val taskDef: TaskDef? = null,
128126
) {
127+
/** Registration of the executing task; resolves wired data inputs. */
128+
internal var taskDef: TaskDef? = null
129+
129130
internal companion object {
130131
fun from(
131132
request: StartupDetails,
@@ -146,7 +147,6 @@ data class Context(
146147
)
147148
},
148149
ti = with(request.ti) { TaskInstance(dagId, runId, taskId, mapIndex, tryNumber) },
149-
taskDef = taskDef,
150-
)
150+
).also { it.taskDef = taskDef }
151151
}
152152
}

‎java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/internal/ArgValues.kt‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ object ArgValues {
9494
// is well defined because a TaskInput is a task's only data parameter.
9595
wiredInputs(context, client)?.let { wired ->
9696
warnWiredArity(client, type, wired.size)
97-
return type.cast(decode(resolveWired(wired[0], client), type))
97+
return type.cast(decode(resolveWiredAll(wired.take(1), client).single(), type))
9898
?: throw missingInput(wired[0], type.simpleName)
9999
}
100100
val input = newInput(type)
@@ -271,15 +271,6 @@ object ArgValues {
271271
is LiteralArg<*> -> MissingXComException("Input '$target' is wired to a null literal, so there is nothing to bind.")
272272
}
273273

274-
private fun resolveWired(
275-
input: Arg<*>,
276-
client: Client,
277-
): Any? =
278-
when (input) {
279-
is TaskRef<*> -> client.getXCom(taskId = input.def.id)
280-
is LiteralArg<*> -> input.value
281-
}
282-
283274
/**
284275
* Builds the failure for a binding that resolved to nothing where a value is
285276
* required, naming [target] — the stub argument, or the [TaskInput] field

‎java-sdk/sdk/src/test/kotlin/org/apache/airflow/sdk/ArgTestSupport.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,5 @@ internal fun contextWiredWith(inputs: List<Arg<*>>): Context {
107107
val def = TaskDef("t", NoopTask::class.java)
108108
DagDef("d").addTask(def)
109109
def.inputs += inputs
110-
return taskContext().copy(taskDef = def)
110+
return taskContext().also { it.taskDef = def }
111111
}

‎java-sdk/sdk/src/test/kotlin/org/apache/airflow/sdk/internal/ArgValuesTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ internal class ArgValuesTest {
121121
val def = TaskDef("consumer", NoopArgTask::class.java)
122122
dag.addTask(def)
123123
def.inputs += inputs
124-
return contextWithoutTaskDef().copy(taskDef = def)
124+
return contextWithoutTaskDef().also { it.taskDef = def }
125125
}
126126

127127
private fun contextWithoutTaskDef(): Context =

0 commit comments

Comments
 (0)