Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

[MISC] Fixed notification plugin loading related issue (#1657)

Chandrasekharan M9cc47bdab32d
diff --git a/backend/adapter_processor_v2/views.py b/backend/adapter_processor_v2/views.py
index 046f80bd4..3e59d1259 100644
--- a/backend/adapter_processor_v2/views.py
+++ b/backend/adapter_processor_v2/views.py
@@ -12,6 +12,7 @@ from permissions.permission import (
IsOwner,
IsOwnerOrSharedUserOrSharedToOrg,
)
+from plugins import get_plugin
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.request import Request
@@ -44,6 +45,10 @@ from adapter_processor_v2.serializers import (
from .constants import AdapterKeys as constant
from .models import AdapterInstance, UserDefaultAdapter
+notification_plugin = get_plugin("notification")
+if notification_plugin:
+ from plugins.notification.constants import ResourceType
+
logger = logging.getLogger(__name__)
@@ -342,40 +347,34 @@ class AdapterInstanceViewSet(ModelViewSet):
# Send email notifications to newly shared users
if response.status_code == 200 and AdapterKeys.SHARED_USERS in request.data:
try:
- from plugins import get_plugin
-
- notification_plugin = get_plugin("notification")
- if notification_plugin:
- from plugins.notification.constants import ResourceType
-
- adapter.refresh_from_db()
- new_shared_users = set(adapter.shared_users.all())
- newly_shared_users = new_shared_users - current_shared_users
-
- if newly_shared_users:
- # Map adapter type to specific resource type
- adapter_type_to_resource = {
- "LLM": ResourceType.LLM.value,
- "EMBEDDING": ResourceType.EMBEDDING.value,
- "VECTOR_DB": ResourceType.VECTOR_DB.value,
- "X2TEXT": ResourceType.X2TEXT.value,
- }
-
- resource_type = adapter_type_to_resource.get(
- adapter.adapter_type, ResourceType.LLM.value
- )
+ adapter.refresh_from_db()
+ new_shared_users = set(adapter.shared_users.all())
+ newly_shared_users = new_shared_users - current_shared_users
+
+ if newly_shared_users:
+ # Map adapter type to specific resource type
+ adapter_type_to_resource = {
+ "LLM": ResourceType.LLM.value,
+ "EMBEDDING": ResourceType.EMBEDDING.value,
+ "VECTOR_DB": ResourceType.VECTOR_DB.value,
+ "X2TEXT": ResourceType.X2TEXT.value,
+ }
+
+ resource_type = adapter_type_to_resource.get(
+ adapter.adapter_type, ResourceType.LLM.value
+ )
- # Get notification service from plugin
- service_class = notification_plugin["service_class"]
- notification_service = service_class()
- notification_service.send_sharing_notification(
- resource_type=resource_type,
- resource_name=adapter.adapter_name,
- resource_id=str(adapter.id),
- shared_by=request.user,
- shared_to=list(newly_shared_users),
- resource_instance=adapter,
- )
+ # Get notification service from plugin
+ service_class = notification_plugin["service_class"]
+ notification_service = service_class()
+ notification_service.send_sharing_notification(
+ resource_type=resource_type,
+ resource_name=adapter.adapter_name,
+ resource_id=str(adapter.id),
+ shared_by=request.user,
+ shared_to=list(newly_shared_users),
+ resource_instance=adapter,
+ )
except Exception as e:
logger.exception(f"Failed to send sharing notification: {e}")
diff --git a/backend/api_v2/api_deployment_views.py b/backend/api_v2/api_deployment_views.py
index 7174547e0..a7aeeb701 100644
--- a/backend/api_v2/api_deployment_views.py
+++ b/backend/api_v2/api_deployment_views.py
@@ -34,10 +34,7 @@ from api_v2.serializers import (
SharedUserListSerializer,
)
-# Check if notification plugin is available
notification_plugin = get_plugin("notification")
-
-# Import constants from notification plugin if available
if notification_plugin:
from plugins.notification.constants import ResourceType
diff --git a/backend/connector_v2/views.py b/backend/connector_v2/views.py
index 1641b8536..b03035ad1 100644
--- a/backend/connector_v2/views.py
+++ b/backend/connector_v2/views.py
@@ -9,6 +9,7 @@ from connector_processor.exceptions import OAuthTimeOut
from django.db import IntegrityError
from django.db.models import ProtectedError, QuerySet
from permissions.permission import IsOwner, IsOwnerOrSharedUserOrSharedToOrg
+from plugins import get_plugin
from rest_framework import status, viewsets
from rest_framework.request import Request
from rest_framework.response import Response
@@ -24,16 +25,11 @@ from .exceptions import DeleteConnectorInUseError
from .models import ConnectorInstance
from .serializers import ConnectorInstanceSerializer
-try:
+notification_plugin = get_plugin("notification")
+if notification_plugin:
from plugins.notification.constants import ResourceType
from plugins.notification.sharing_notification import SharingNotificationService
- NOTIFICATION_PLUGIN_AVAILABLE = True
- sharing_notification_service = SharingNotificationService()
-except ImportError:
- NOTIFICATION_PLUGIN_AVAILABLE = False
- sharing_notification_service = None
-
logger = logging.getLogger(__name__)
@@ -214,7 +210,7 @@ class ConnectorInstanceViewSet(viewsets.ModelViewSet):
if (
response.status_code == 200
and "shared_users" in request.data
- and NOTIFICATION_PLUGIN_AVAILABLE
+ and bool(notification_plugin)
):
try:
instance.refresh_from_db()
@@ -223,7 +219,7 @@ class ConnectorInstanceViewSet(viewsets.ModelViewSet):
if newly_shared_users:
# Only send notifications if there are newly shared users
- sharing_notification_service.send_sharing_notification(
+ SharingNotificationService().send_sharing_notification(
resource_type=ResourceType.CONNECTOR.value,
resource_name=instance.connector_name,
resource_id=str(instance.id),
diff --git a/backend/pipeline_v2/views.py b/backend/pipeline_v2/views.py
index 02625a52f..64b6a8b26 100644
--- a/backend/pipeline_v2/views.py
+++ b/backend/pipeline_v2/views.py
@@ -33,12 +33,8 @@ from pipeline_v2.serializers.execute import (
)
from pipeline_v2.serializers.sharing import SharedUserListSerializer
-# Check if notification plugin is available
notification_plugin = get_plugin("notification")
-NOTIFICATION_PLUGIN_AVAILABLE = notification_plugin is not None
-
-# Import constants from notification plugin if available
-if NOTIFICATION_PLUGIN_AVAILABLE:
+if notification_plugin:
from plugins.notification.constants import ResourceType
logger = logging.getLogger(__name__)
@@ -135,7 +131,7 @@ class PipelineViewSet(viewsets.ModelViewSet):
if (
response.status_code == 200
and "shared_users" in request.data
- and NOTIFICATION_PLUGIN_AVAILABLE
+ and notification_plugin
):
try:
instance.refresh_from_db()
diff --git a/backend/workflow_manager/workflow_v2/views.py b/backend/workflow_manager/workflow_v2/views.py
index aa4f869a9..e2d8e21ac 100644
--- a/backend/workflow_manager/workflow_v2/views.py
+++ b/backend/workflow_manager/workflow_v2/views.py
@@ -58,12 +58,8 @@ from workflow_manager.workflow_v2.workflow_helper import (
WorkflowSchemaHelper,
)
-# Check if notification plugin is available
notification_plugin = get_plugin("notification")
-NOTIFICATION_PLUGIN_AVAILABLE = notification_plugin is not None
-
-# Import constants from notification plugin if available
-if NOTIFICATION_PLUGIN_AVAILABLE:
+if notification_plugin:
from plugins.notification.constants import ResourceType
logger = logging.getLogger(__name__)
@@ -156,7 +152,7 @@ class WorkflowViewSet(viewsets.ModelViewSet):
if (
response.status_code == 200
and "shared_users" in request.data
- and NOTIFICATION_PLUGIN_AVAILABLE
+ and bool(notification_plugin)
):
try:
# Get updated workflow to compare shared users