fix(trigger): sync plugin relationships on publish (#41756)

This commit is contained in:
bucketbase26 2026-09-04 08:33:48 +00:00 committed by GitHub
parent 7919df7ef5
commit b5ee943a63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import logging
from events.app_event import app_draft_workflow_was_synced
from events.app_event import app_draft_workflow_was_synced, app_published_workflow_was_updated
from models.model import App, AppMode
from models.workflow import Workflow
from services.trigger.trigger_service import TriggerService
@ -9,14 +9,26 @@ logger = logging.getLogger(__name__)
@app_draft_workflow_was_synced.connect
def handle(sender, synced_draft_workflow: Workflow, **kwargs):
@app_published_workflow_was_updated.connect
def handle(
sender,
synced_draft_workflow: Workflow | None = None,
published_workflow: Workflow | None = None,
**kwargs,
):
"""
While creating a workflow or updating a workflow, we may need to sync
its plugin trigger relationships in DB.
Sync plugin trigger relationships when a draft changes or is published.
The published workflow must be reconciled as well because production trigger
dispatch relies on these relationships, while debug dispatch does not.
"""
app: App = sender
if app.mode != AppMode.WORKFLOW.value:
# only handle workflow app, chatflow is not supported yet
return
TriggerService.sync_plugin_trigger_relationships(app, synced_draft_workflow)
workflow = published_workflow if published_workflow is not None else synced_draft_workflow
if workflow is None:
return
TriggerService.sync_plugin_trigger_relationships(app, workflow)

View File

@ -0,0 +1,31 @@
from types import SimpleNamespace
from typing import cast
from unittest.mock import patch
from events.event_handlers.sync_plugin_trigger_when_app_created import handle
from models.model import AppMode
from models.workflow import Workflow
def test_syncs_plugin_trigger_relationships_from_published_workflow() -> None:
app = SimpleNamespace(mode=AppMode.WORKFLOW.value)
published_workflow = cast(Workflow, object())
with patch(
"events.event_handlers.sync_plugin_trigger_when_app_created.TriggerService.sync_plugin_trigger_relationships"
) as sync_relationships:
handle(app, published_workflow=published_workflow)
sync_relationships.assert_called_once_with(app, published_workflow)
def test_keeps_draft_workflow_relationship_sync() -> None:
app = SimpleNamespace(mode=AppMode.WORKFLOW.value)
draft_workflow = cast(Workflow, object())
with patch(
"events.event_handlers.sync_plugin_trigger_when_app_created.TriggerService.sync_plugin_trigger_relationships"
) as sync_relationships:
handle(app, synced_draft_workflow=draft_workflow)
sync_relationships.assert_called_once_with(app, draft_workflow)