Skip to content

Return null from Java SDK getVariable for missing Variables - #75920

Open
aaron-y-chen wants to merge 2 commits into
apache:mainfrom
aaron-y-chen:java-sdk-variable-not-found-null
Open

aaron-y-chen wants to merge 2 commits into
apache:mainfrom
aaron-y-chen:java-sdk-variable-not-found-null

Conversation

@aaron-y-chen

Copy link
Copy Markdown
Contributor

Summary

Client.getVariable(key) in the Java SDK is documented (KDoc and java.rst) to return null when the Variable does not exist, but it threw ApiError instead. A task reading an optional Variable failed rather than falling back to a default, and since ApiError carries no error type, callers could only tell "missing" apart from real failures by parsing the message.

The supervisor reports a missing Variable as ErrorResponse(VARIABLE_NOT_FOUND). getVariable now handles it with communicateOrNullIf, the same way getTaskStateStore handles TASK_STORE_NOT_FOUND: VARIABLE_NOT_FOUND returns null, and any other error still raises ApiError.

Behavior change

java-sdk 1.0.0-beta1 shipped with the throwing behavior. Code that catches ApiError to detect a missing Variable now gets null instead.

Testing

  • CommsTest: VARIABLE_NOT_FOUND returns null; any other error response still raises ApiError.
  • E2E: WriteAndDeleteVariable reads the Variable back after deleting it and fails unless the result is null. Verified locally: the Dag run fails without the fix (ApiError: [VARIABLE_NOT_FOUND]) and succeeds with it.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Opus 5.5) following the guidelines

Comment thread java-sdk/sdk/src/test/kotlin/org/apache/airflow/sdk/execution/CommTest.kt Outdated
@aaron-y-chen

Copy link
Copy Markdown
Contributor Author

unrelated CI failure on bzip2/libbz2-1.0 in add-build-essential-extend

Comment on lines +186 to +187
// An ErrorResponse carrying a typed `error` code and a one-entry `detail`, as the supervisor sends it.
private fun typedErrorFrame(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably do the same for success replies, but this is probably out of this PR’s scope.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants