Skip to content

refactor(api): type webhook data extraction with RawWebhookDataDict TypedDict#34486

Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom
YB0y:refactor/typed-dict-webhook-service
Apr 3, 2026
Merged

refactor(api): type webhook data extraction with RawWebhookDataDict TypedDict#34486
asukaminato0721 merged 1 commit intolanggenius:mainfrom
YB0y:refactor/typed-dict-webhook-service

Conversation

@YB0y
Copy link
Copy Markdown
Contributor

@YB0y YB0y commented Apr 2, 2026

Summary

  • Add RawWebhookDataDict TypedDict with keys method, headers, query_params, body, files
  • Annotate return types of extract_webhook_data, extract_and_validate_webhook_data, and _process_and_validate_data

Why this change

extract_webhook_data constructs a dict with 5 well-documented fixed keys but was typed as dict[str, Any]. The same shape flows through _process_and_validate_data and extract_and_validate_webhook_data. A TypedDict makes the webhook data contract explicit at every layer.

Changes

  • services/trigger/webhook_service.py: Define RawWebhookDataDict, update 3 method signatures

Test plan

  • ruff check passes

Part of #32863 (services/trigger/webhook_service.py)

@YB0y YB0y requested review from Mairuis and Yeuoly as code owners April 2, 2026 15:44
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Apr 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-02 15:45:21.470739938 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-02 15:45:12.709762305 +0000
@@ -14,6 +14,10 @@
   --> controllers/console/setup.py:65:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/version.py:30:2
+ERROR Argument `dict[str, dict[str, str] | dict[Unknown, Unknown] | str] | RawWebhookDataDict` is not assignable to parameter `webhook_data` with type `dict[str, Any]` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
+  --> controllers/trigger/webhook.py:56:68
+ERROR Argument `dict[str, dict[str, str] | dict[Unknown, Unknown] | str] | RawWebhookDataDict` is not assignable to parameter `webhook_data` with type `dict[str, Any]` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
+  --> controllers/trigger/webhook.py:86:64
 ERROR Class member `EasyUIBasedGenerateTaskPipeline._application_generate_entity` overrides parent class `BasedGenerateTaskPipeline` in an inconsistent manner [bad-override]
   --> core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py:75:5
 ERROR `+=` is not supported between `list[PromptMessageContentUnionTypes]` and `str` [unsupported-operation]
@@ -343,6 +347,8 @@
   --> services/document_indexing_proxy/duplicate_document_indexing_task_proxy.py:15:5
 ERROR `handled_tenant_count` was assigned in the current scope before the nonlocal declaration [unknown-name]
   --> services/plugin/plugin_migration.py:81:34
+ERROR Argument `RawWebhookDataDict` is not assignable to parameter `webhook_data` with type `dict[str, Any]` in function `WebhookService._validate_http_metadata` [bad-argument-type]
+   --> services/trigger/webhook_service.py:174:57
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Returned type `EndUser | Unknown | None` is not assignable to declared return type `Account | EndUser` [bad-return]

@YB0y YB0y force-pushed the refactor/typed-dict-webhook-service branch from a5e596a to 1e81fad Compare April 2, 2026 15:57
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-02 16:00:19.015568062 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-02 16:00:09.538546845 +0000
@@ -6658,6 +6658,28 @@
    --> tests/unit_tests/services/test_webhook_service.py:515: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:535:83
+ERROR Argument `dict[str, dict[str, 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.py:1021:53
+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.py:1044:51
+ERROR Argument `dict[str, dict[str, int]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
+    --> tests/unit_tests/services/test_webhook_service.py:1077:64
+ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
 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:1290:61
 ERROR Missing required key `id` for TypedDict `NodeConfigDict` [bad-typed-dict-key]

@YB0y YB0y force-pushed the refactor/typed-dict-webhook-service branch from 1e81fad to 86233a3 Compare April 2, 2026 16:31
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-02 16:32:29.486869419 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-02 16:32:19.929931044 +0000
@@ -6658,6 +6658,28 @@
    --> tests/unit_tests/services/test_webhook_service.py:515: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:535:83
+ERROR Argument `dict[str, dict[str, 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.py:1021:53
+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.py:1044:51
+ERROR Argument `dict[str, dict[str, int]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
+    --> tests/unit_tests/services/test_webhook_service.py:1077:64
+ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
+    --> tests/unit_tests/services/test_webhook_service.py:1139:68
 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:1290:61
 ERROR Missing required key `id` for TypedDict `NodeConfigDict` [bad-typed-dict-key]

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 3, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 3, 2026
Merged via the queue into langgenius:main with commit 9a6222f Apr 3, 2026
27 checks passed
@YB0y YB0y deleted the refactor/typed-dict-webhook-service branch April 8, 2026 13:35
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants