FrankYang0529 commented on code in PR #69827:
URL: https://github.com/apache/airflow/pull/69827#discussion_r3649030752
##########
java-sdk/processor/src/test/kotlin/org/apache/airflow/sdk/BuilderTest.kt:
##########
@@ -297,4 +297,21 @@ class BuilderTest {
"Cannot create task from vararg function t1",
)
}
+
+ @Test
+ @DisplayName("fail compilation when dag class is a non-static inner class")
+ fun failCompilationWhenDagClassIsNonStaticInner() {
+ val compilation =
+ compile(
+ """
+ package org.apache.airflow.example;
+ import org.apache.airflow.sdk.Builder;
+ public class TestExample {
+ @Builder.Dag
+ public class InnerDag { @Builder.Task(id = "foo") public void t1()
{} }
+ }
+ """,
+ )
+ assertThat(compilation).failed()
Review Comment:
Sorry for the late reply. Updated it to
```
assertThat(compilation).hadErrorContaining(
"an enclosing instance that contains
org.apache.airflow.example.TestExample.InnerDag is required",
)
```
##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt:
##########
@@ -71,17 +73,22 @@ internal object TaskRunner {
client: Client,
): Any {
val task = bundle.dags[request.ti.dagId]?.tasks[request.ti.taskId] ?:
return TaskResult.of(TaskState.State.REMOVED)
+ val instance =
+ try {
+ task.getDeclaredConstructor().newInstance()
+ } catch (e: Throwable) {
+ logger.error(
+ "Cannot instantiate task class. A task class must be concrete and
declare a public no-argument constructor",
+ mapOf("ti" to request.ti, "taskClass" to task.name, "error" to e,
"trace" to e.stackTraceToString()),
+ )
+ return TaskResult.failure(request.tiContext.shouldRetry)
+ }
Review Comment:
Thanks for the review. Updated it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]