Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore(api): convert AppContext from ABC to Protocol (#37203)

Eric Caoa8977be9991c
diff --git a/api/context/execution_context.py b/api/context/execution_context.py
index 6fb3ca19712..ea3d9969290 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 3ce4bb753b9..82411e1b10d 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."""