From a8977be9991cde5f667cda14cb93fe12dfdbad42 Mon Sep 17 00:00:00 2001 From: Eric Cao Date: Tue, 9 Jun 2026 11:16:39 +0800 Subject: [PATCH] chore(api): convert AppContext from ABC to Protocol (#37203) --- api/context/execution_context.py | 14 +++++--------- .../workflow/context/test_execution_context.py | 9 --------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/api/context/execution_context.py b/api/context/execution_context.py index 6fb3ca1971..ea3d996929 100644 --- a/api/context/execution_context.py +++ b/api/context/execution_context.py @@ -7,7 +7,6 @@ consumes injected context managers when it needs to preserve thread-local state. import contextvars import threading -from abc import ABC, abstractmethod from collections.abc import Callable, Generator from contextlib import AbstractContextManager, contextmanager from typing import Any, Protocol, final, override, runtime_checkable @@ -15,28 +14,25 @@ from typing import Any, Protocol, final, override, runtime_checkable from pydantic import BaseModel -class AppContext(ABC): +class AppContext(Protocol): """ - Abstract application context interface. + Application context interface. Application adapters can implement this to restore framework-specific state such as Flask app context around worker execution. """ - @abstractmethod def get_config(self, key: str, default: Any = None) -> Any: """Get configuration value by key.""" - raise NotImplementedError + ... - @abstractmethod def get_extension(self, name: str) -> Any: """Get application extension by name.""" - raise NotImplementedError + ... - @abstractmethod def enter(self) -> AbstractContextManager[None]: """Enter the application context.""" - raise NotImplementedError + ... @runtime_checkable diff --git a/api/tests/unit_tests/core/workflow/context/test_execution_context.py b/api/tests/unit_tests/core/workflow/context/test_execution_context.py index 3ce4bb753b..82411e1b10 100644 --- a/api/tests/unit_tests/core/workflow/context/test_execution_context.py +++ b/api/tests/unit_tests/core/workflow/context/test_execution_context.py @@ -20,15 +20,6 @@ from context.execution_context import ( ) -class TestAppContext: - """Test AppContext abstract base class.""" - - def test_app_context_is_abstract(self): - """Test that AppContext cannot be instantiated directly.""" - with pytest.raises(TypeError): - AppContext() # type: ignore - - class TestNullAppContext: """Test NullAppContext implementation."""