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


##########
task-sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -127,22 +135,28 @@ def _convert_variable_result_to_variable(var_result: 
VariableResult, deserialize
 
 
 def _get_connection(conn_id: str) -> Connection:
+    from airflow.sdk.execution_time.cache import SecretCache
     from airflow.sdk.execution_time.supervisor import 
ensure_secrets_backend_loaded
 
-    # TODO: check cache first (also in _async_get_connection)
-    # enabled only if SecretCache.init() has been called first
+    # Check cache first (optional; only on dag processor)
+    try:
+        uri = SecretCache.get_connection_uri(conn_id)
+        from airflow.sdk.definitions.connection import Connection
+
+        conn = Connection.from_uri(uri, conn_id=conn_id)
+        _mask_connection_secrets(conn)
+        return conn
+    except SecretCache.NotPresentException:
+        pass  # continue to backends
 
     # iterate over configured backends if not in cache (or expired)
     backends = ensure_secrets_backend_loaded()
     for secrets_backend in backends:
         try:
-            conn = secrets_backend.get_connection(conn_id=conn_id)
+            conn = secrets_backend.get_connection(conn_id=conn_id)  # type: 
ignore[assignment]

Review Comment:
   Why is the mypy ignore needed?



##########
task-sdk/tests/task_sdk/execution_time/test_context_cache.py:
##########
@@ -0,0 +1,332 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations

Review Comment:
   Call this file test_cache.py or test_secret_cache.py instead?



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