amoghrajesh commented on code in PR #72329:
URL: https://github.com/apache/airflow/pull/72329#discussion_r4181371519


##########
task-sdk/tests/task_sdk/definitions/test_variables.py:
##########
@@ -204,6 +203,139 @@ def test_keys_raises_on_unexpected_response_type(self, 
mock_supervisor_comms):
             list(results)
 
 
+class TestAsyncVariables:
+    @pytest.mark.asyncio
+    @pytest.mark.parametrize(
+        ("deserialize_json", "value", "expected_value"),
+        [
+            pytest.param(False, "my_value", "my_value", id="simple-value"),
+            pytest.param(
+                True,
+                '{"key": "value", "number": 42, "flag": true}',
+                {"key": "value", "number": 42, "flag": True},
+                id="deser-object-value",
+            ),
+        ],
+    )
+    async def test_avar_get(self, deserialize_json, value, expected_value, 
mock_supervisor_comms):

Review Comment:
   `test_avar_get` still asserts only the returned value. Its siblings, 
`test_avar_set` and `test_avar_delete` both assert what was sent. Add the same 
check so a wrong outbound message fails the test.



##########
task-sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -382,6 +400,52 @@ def _get_variable(key: str, deserialize_json: bool) -> Any:
     )
 
 
+async def _async_get_variable(key: str, deserialize_json: bool) -> Any:
+    from airflow.sdk.execution_time.cache import SecretCache
+    from airflow.sdk.execution_time.supervisor import 
ensure_secrets_backend_loaded
+
+    # Check cache first
+    try:
+        var_val = SecretCache.get_variable(key)
+        if var_val is not None:
+            return await _async_mask_and_deserialize_variable(var_val, key, 
deserialize_json)
+    except SecretCache.NotPresentException:
+        pass  # Continue to check backends
+
+    backends = ensure_secrets_backend_loaded()
+
+    # Iterate over backends if not in cache (or expired)
+    for secrets_backend in backends:
+        try:
+            async_method = getattr(secrets_backend, "aget_variable", None)
+            if async_method is not None:
+                var_val = await async_method(key=key)
+            else:
+                var_val = await 
asyncio.to_thread(secrets_backend.get_variable, key=key)
+            if var_val is not None:
+                # Save raw value before deserialization to maintain cache 
consistency
+                SecretCache.save_variable(key, var_val)
+                return await _async_mask_and_deserialize_variable(var_val, 
key, deserialize_json)
+        except AirflowSecretsBackendAccessDenied:

Review Comment:
   This is still untested. Although the sync twin at `:386` has no test either, 
so this is not a regression. Worth one test covering both.
   
   



-- 
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]

Reply via email to