This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 04c30dcc4e6 fix: make _get_ssl_context_cached a static method (#57401)
04c30dcc4e6 is described below
commit 04c30dcc4e6a0899d19063cfeaf7f521b26e7695
Author: Wei Lee <[email protected]>
AuthorDate: Tue Oct 28 13:22:18 2025 +0800
fix: make _get_ssl_context_cached a static method (#57401)
---
task-sdk/src/airflow/sdk/api/client.py | 4 ++--
task-sdk/tests/task_sdk/api/test_client.py | 13 ++++++++++---
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/task-sdk/src/airflow/sdk/api/client.py
b/task-sdk/src/airflow/sdk/api/client.py
index d73c405cbe7..0a3de028941 100644
--- a/task-sdk/src/airflow/sdk/api/client.py
+++ b/task-sdk/src/airflow/sdk/api/client.py
@@ -851,9 +851,9 @@ def _should_retry_api_request(exception: BaseException) ->
bool:
class Client(httpx.Client):
- @classmethod
@lru_cache()
- def _get_ssl_context_cached(cls, ca_file: str, ca_path: str | None = None)
-> ssl.SSLContext:
+ @staticmethod
+ def _get_ssl_context_cached(ca_file: str, ca_path: str | None = None) ->
ssl.SSLContext:
"""Cache SSL context to prevent memory growth from repeated context
creation."""
ctx = ssl.create_default_context(cafile=ca_file)
if ca_path:
diff --git a/task-sdk/tests/task_sdk/api/test_client.py
b/task-sdk/tests/task_sdk/api/test_client.py
index abeda2acd31..ed3997aefc6 100644
--- a/task-sdk/tests/task_sdk/api/test_client.py
+++ b/task-sdk/tests/task_sdk/api/test_client.py
@@ -1370,10 +1370,10 @@ class TestHITLOperations:
class TestSSLContextCaching:
- def setup_method(self):
+ @pytest.fixture(autouse=True)
+ def clear_ssl_context_cache(self):
Client._get_ssl_context_cached.cache_clear()
-
- def teardown_method(self):
+ yield
Client._get_ssl_context_cached.cache_clear()
def test_cache_hit_on_same_parameters(self):
@@ -1382,6 +1382,13 @@ class TestSSLContextCaching:
ctx2 = Client._get_ssl_context_cached(ca_file, None)
assert ctx1 is ctx2
+ def test_cache_miss_if_cache_cleared(self):
+ ca_file = certifi.where()
+ ctx1 = Client._get_ssl_context_cached(ca_file, None)
+ Client._get_ssl_context_cached.cache_clear()
+ ctx2 = Client._get_ssl_context_cached(ca_file, None)
+ assert ctx1 is not ctx2
+
def test_cache_miss_on_different_parameters(self):
ca_file = certifi.where()