Fix Java SDK numeric XCom casting and remove unused XCom key field#68983
Conversation
jason810496
left a comment
There was a problem hiding this comment.
Nice catch! LGTM overall.
|
Hmm, I wonder if we should do this since Python’s Taskflow API does not support using an argument to pull from a custom key; it only supports the return value. Maybe we should remove |
5df4f1f to
a55d99f
Compare
a55d99f to
b9b4f37
Compare
Agreed, remove key from |
b9b4f37 to
a95f544
Compare
uranusjr
left a comment
There was a problem hiding this comment.
I just realized, we probably should mention in docs if you set up Builder.XCom to read into a primitive, but fail to actually push it, the cast would fail with a NullPointerException since there’s no way to represent a null in primitives. (By contrast, if you use e.g. Integer, you’d “safely” get null.)
We might want to add a case to emit a cleaner exception instead. This should be done in a separate PR.
I will do it in the next PR. Thank you. |
Generate accessors that widen through Number instead: primitive params use ((Number) x).intValue(), and boxed params use Optional.ofNullable(...).orElse(null) so an absent XCom stays null. Add a java_xcom_casting_example DAG and processor tests covering int->long->double widening and an absent boxed value. Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
a95f544 to
2af0c39
Compare
1. Fix numeric XCom casting
Widen numeric XCom values through
Numberinstead of casting the boxed value to the declared type:((Number) client.getXCom(...)).intValue()Optional.ofNullable((Number) client.getXCom(...)).map(Number::intValue).orElse(null), so an absent XCom staysnullrather than throwing.2. Remove the unused
keyfield fromBuilder.XCom@Builder.XComexposed akeyfield, but the annotation processor only readstaskwhen generating thegetXComcall, sokeynever affected the generated code.Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.