diff --git a/task-sdk/src/airflow/sdk/api/client.py b/task-sdk/src/airflow/sdk/api/client.py index d73c405cbe7f5..0a3de02894150 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 abeda2acd31ea..ed3997aefc6cc 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 @@ def handle_request(request: httpx.Request) -> httpx.Response: 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 @@ def test_cache_hit_on_same_parameters(self): 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()