Repository navigation
Add async Variable methods (aget, aset, adelete, akeys) - #72329
Merged
Merged
Conversation
Fix Variable.akeys: wrapping an async call inside lazy_object_proxy.Proxy is invalid because await cannot be used inside a plain lambda. The method now awaits _async_get_variable_keys directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dabla
force-pushed
the
feature/add-async-accessors-variable
branch
from
August 31, 2026 14:43
93418a6 to
6c0e252
Compare
amoghrajesh
requested changes
Sep 15, 2026
amoghrajesh
left a comment
Contributor
There was a problem hiding this comment.
Requesting changes to avoid accidental merge, directionally good, but there's work needed.
…e run the sync one via asyncio.to_thread
…ctly Avoid importing and reassigning AsyncMock in every test; the fixture's asend is already an AsyncMock, so tests can set return_value/side_effect on it directly, per top-level import convention. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cMock imports Same cleanup as test_variables.py: set return_value/side_effect directly on the fixture's mock_supervisor_comms.asend instead of importing and reassigning AsyncMock per test; move json import to the top of the file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dabla
force-pushed
the
feature/add-async-accessors-variable
branch
from
September 15, 2026 12:09
af48dc4 to
f8be671
Compare
This was referenced Sep 20, 2026
dabla
added a commit
to dabla/airflow
that referenced
this pull request
Sep 30, 2026
The error an iterated async task gets for a synchronous SDK call already points at Variable.aget/aset, which apache#72329 adds; the class docstring still said Variable had no async equivalent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amoghrajesh
reviewed
Sep 30, 2026
amoghrajesh
left a comment
Contributor
There was a problem hiding this comment.
Looking better, some comments.
json is already imported at module level in context.py, and _VARIABLE_KEYS_PAGE_SIZE is now imported once at the top of each test module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mirror the sync VariableAccessor masking tests for _async_get_variable so _async_mask_and_deserialize_variable and the SecretCache hit path are covered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dabla
added a commit
to dabla/airflow
that referenced
this pull request
Oct 1, 2026
The error an iterated async task gets for a synchronous SDK call already points at Variable.aget/aset, which apache#72329 adds; the class docstring still said Variable had no async equivalent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amoghrajesh
approved these changes
Oct 5, 2026
amoghrajesh
left a comment
Contributor
There was a problem hiding this comment.
The PR body is wrong. It mentions "The four underlying async* functions were already implemented" and lists them as background. This PR adds all four, along with _async_mask_and_deserialize_variable, please update it.
Looks good otherwise with 2 nits.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
_async_get_variable re-raises AirflowSecretsBackendAccessDenied instead of asking the next secrets backend. The sync twin is covered in test_secrets.py; this pins the async one. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dabla
added a commit
to dabla/airflow
that referenced
this pull request
Oct 5, 2026
The error an iterated async task gets for a synchronous SDK call already points at Variable.aget/aset, which apache#72329 adds; the class docstring still said Variable had no async equivalent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dabla
added a commit
to dabla/airflow
that referenced
this pull request
Oct 8, 2026
The error an iterated async task gets for a synchronous SDK call already points at Variable.aget/aset, which apache#72329 adds; the class docstring still said Variable had no async equivalent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add async Variable methods (
aget,aset,adelete,akeys) with testsThis PR adds async counterparts to all synchronous
Variablemethods.What changed
Variableclass (task-sdk/src/airflow/sdk/definitions/variable.py)Four new async class methods:
Variable.agetVariable.get_async_get_variable; falls back todefault(masked) onVARIABLE_NOT_FOUNDVariable.asetVariable.set_async_set_variableVariable.adeleteVariable.delete_async_delete_variableVariable.akeysVariable.keys_async_get_variable_keysand returns the resolved list; unlikekeysit is not lazyContext helpers (
task-sdk/src/airflow/sdk/execution_time/context.py)This PR also adds the five helpers behind those methods. Each mirrors its sync twin:
_async_mask_and_deserialize_variablemasks the raw value and, withdeserialize_json, the decoded value throughamask_secret._async_get_variablechecksSecretCache, then asks each secrets backend:aget_variablewhen the backend has one, otherwiseget_variableviaasyncio.to_thread.ExecutionAPISecretsBackend.aget_variablereaches theExecution API via
asend. An authoritative deny(
AirflowSecretsBackendAccessDenied) is re-raised and never falls through tothe next backend.
_async_set_variablewarns when a worker-side secrets backend already holdsthe key (checked via
asyncio.to_thread), sendsPutVariableviaasend,and invalidates the cache.
_async_delete_variablesendsDeleteVariableviaasendand invalidatesthe cache.
_async_get_variable_keyspages throughGetVariableKeysrequests viaasend.Tests
test_variables.pyTestAsyncVariablesandTestAsyncVariableKeysmirror the sync test cases:test_avar_get: plain and JSON-deserialized values; verifies theGetVariablerequesttest_avar_get_returns_default_when_not_found,test_avar_get_raises_when_not_found_without_defaulttest_avar_set: plain and JSON-serialized values; verifies thePutVariablepayloadtest_avar_delete: verifiesDeleteVariableis sent viaasendtest_akeys: prefix filtering (all / with prefix / empty)test_akeys_paginates_when_results_exceed_page_sizetest_akeys_raises_on_error_responsetest_akeys_raises_on_unexpected_response_typetest_context.pyTestAsyncVariableContexttests the context helpers directly:_async_get_variable: from the API, from a secrets backend, not found raises,a
PERMISSION_DENIEDfrom the Execution API raises and the next backend is never asked_async_set_variable: plain value, JSON-serialized value, warning on a conflicting backend_async_delete_variable: sendsDeleteVariable_async_get_variable_keys: prefix filtering, pagination, error, unexpected responseWas generative AI tooling used to co-author this PR?
GitHub Copilot (Claude Sonnet 4.6), Claude Code
{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.