Skip to content

fix(webhook): align ToolFile owner with Trigger EndUser for multipart uploads - #42988

Closed
leilei3167 wants to merge 2 commits into
langgenius:mainfrom
leilei3167:fix/issue-42987-webhook-toolfile-owner
Closed

leilei3167 wants to merge 2 commits into
langgenius:mainfrom
leilei3167:fix/issue-42987-webhook-toolfile-owner

Conversation

@leilei3167

Copy link
Copy Markdown
Contributor

Fixes #42987

Summary

Webhook multipart uploads created ToolFile rows with user_id=webhook_trigger.created_by (the workflow owner account). Async webhook runs execute as a Trigger EndUser, so file access checks could not find those uploads (ToolFile not found).

_create_file_from_binary() now resolves the same Trigger EndUser used by trigger_workflow_execution() and stores uploaded files under that identity.

Testing

  • Old red: pytest -o addopts= tests/unit_tests/services/test_webhook_service_additional.py::TestWebhookServiceExtractionFallbacks::test_create_file_from_binary_should_call_tool_file_manager_and_file_factory fails on main (expects Trigger EndUser id, code used account id).
  • New green: same command passes with this change.
  • pytest -o addopts= tests/unit_tests/services/test_webhook_service.py tests/unit_tests/services/test_webhook_service_additional.py — 75 passed.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 26, 2026
@ghfind-review ghfind-review Bot added the review: medium ghfind author score; see https://ghfind.com label Sep 26, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-09-26 20:21:18.310439991 +0000
+++ /tmp/pyrefly_pr.txt	2026-09-26 20:21:09.838363349 +0000
@@ -6709,27 +6709,27 @@
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
    --> tests/unit_tests/services/test_webhook_service.py:552:79
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:794:88
+   --> tests/unit_tests/services/test_webhook_service.py:804:88
 ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:821:83
+   --> tests/unit_tests/services/test_webhook_service.py:831:83
 ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:841:83
+   --> tests/unit_tests/services/test_webhook_service.py:851:83
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:859:86
+   --> tests/unit_tests/services/test_webhook_service.py:869:86
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:878:91
+   --> tests/unit_tests/services/test_webhook_service.py:888:91
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:900:86
+   --> tests/unit_tests/services/test_webhook_service.py:910:86
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:919:86
+   --> tests/unit_tests/services/test_webhook_service.py:929:86
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:937:91
+   --> tests/unit_tests/services/test_webhook_service.py:947:91
 ERROR Argument `dict[str, str | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service_additional.py:249:57
+   --> tests/unit_tests/services/test_webhook_service_additional.py:261:57
 ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service_additional.py:261:55
+   --> tests/unit_tests/services/test_webhook_service_additional.py:273:55
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service_additional.py:273:65
+   --> tests/unit_tests/services/test_webhook_service_additional.py:285:65
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
   --> tests/unit_tests/services/test_workflow_collaboration_service.py:25:56
 ERROR Argument `list[int | str]` is not assignable to parameter `mentioned_user_ids` with type `Sequence[str]` in function `services.workflow_comment_service.WorkflowCommentService._filter_valid_mentioned_user_ids` [bad-argument-type]

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 67.36% 67.36% 0.00%
Strict coverage 66.98% 66.98% 0.00%
Typed symbols 51,311 51,311 0
Untyped symbols 25,003 25,003 0
Modules 3562 3562 0

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.05%. Comparing base (414cce2) to head (bb2616f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
api/services/trigger/webhook_service.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #42988      +/-   ##
==========================================
- Coverage   88.07%   88.05%   -0.02%     
==========================================
  Files        5308     5151     -157     
  Lines      327512   323369    -4143     
  Branches    66277    65169    -1108     
==========================================
- Hits       288443   284732    -3711     
+ Misses      33685    33253     -432     
  Partials     5384     5384              
Flag Coverage Δ
api 87.89% <60.00%> (-0.01%) ⬇️
cli ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leilei3167

Copy link
Copy Markdown
Contributor Author

Closing this. The branch is conflicted, the patch check is red, and there has been no review. Thank you for the time.

@leilei3167 leilei3167 closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: medium ghfind author score; see https://ghfind.com size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webhook file upload fails in async workflow because ToolFile owner differs from Trigger EndUser

1 participant