refactor(api): type workflow run related counts with RelatedCountsDict TypedDict#34530
Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom Apr 6, 2026
Conversation
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-03 13:02:51.515012473 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-03 13:02:42.976049428 +0000
@@ -343,6 +343,16 @@
--> 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 `object` is not assignable to parameter `value` with type `int` in function `WorkflowRunCleanupMetrics._add` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:166:17
+ERROR Cannot set item in `RelatedCountsDict` [unsupported-operation]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:325:29
+ERROR Invalid key for TypedDict `RelatedCountsDict`, got `str` [bad-typed-dict-key]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:325:44
+ERROR Argument `dict[str, int]` is not assignable to parameter `related_counts` with type `RelatedCountsDict | None` in function `WorkflowRunCleanupMetrics.record_batch` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:344:40
+ERROR Argument `dict[str, int]` is not assignable to parameter `related_counts` with type `RelatedCountsDict | None` in function `WorkflowRunCleanupMetrics.record_batch` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:384:36
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]
|
478c26c to
ea8bf61
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-03 13:12:48.014493773 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-03 13:12:39.605615478 +0000
@@ -343,6 +343,16 @@
--> 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 `object` is not assignable to parameter `value` with type `int` in function `WorkflowRunCleanupMetrics._add` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:175:17
+ERROR Cannot set item in `RelatedCountsDict` [unsupported-operation]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:325:29
+ERROR Invalid key for TypedDict `RelatedCountsDict`, got `str` [bad-typed-dict-key]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:325:44
+ERROR Argument `dict[str, int]` is not assignable to parameter `related_counts` with type `RelatedCountsDict | None` in function `WorkflowRunCleanupMetrics.record_batch` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:344:40
+ERROR Argument `dict[str, int]` is not assignable to parameter `related_counts` with type `RelatedCountsDict | None` in function `WorkflowRunCleanupMetrics.record_batch` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:384:36
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]
|
ea8bf61 to
63a5894
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-03 13:35:21.810526404 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-03 13:35:12.982547608 +0000
@@ -343,6 +343,10 @@
--> 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 Cannot set item in `RelatedCountsDict` [unsupported-operation]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:325:29
+ERROR Invalid key for TypedDict `RelatedCountsDict`, got `str` [bad-typed-dict-key]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:325:44
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]
|
63a5894 to
df4c636
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-03 16:22:28.267209835 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-03 16:22:19.575184311 +0000
@@ -343,6 +343,10 @@
--> 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 No matching overload found for function `dict.__init__` called with arguments: (RelatedCountsDict) [no-matching-overload]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:242:53
+ERROR Argument `dict[str, int]` is not assignable to parameter `counts` with type `RelatedCountsDict` in function `WorkflowRunCleanup._format_related_counts` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:407:92
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]
|
df4c636 to
ab1eb51
Compare
Contributor
Pyrefly DiffNo changes detected. |
ab1eb51 to
2d69cf1
Compare
Contributor
Pyrefly DiffNo changes detected. |
2d69cf1 to
197aaeb
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-05 22:45:18.081758602 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-05 22:45:09.239638788 +0000
@@ -343,6 +343,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 `RunsWithRelatedCountsDict` is not assignable to parameter `batch` with type `dict[str, int]` in function `WorkflowRunCleanup._accumulate_related_counts` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:327:73
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]
|
197aaeb to
288bce1
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-05 22:48:48.667594729 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-05 22:48:39.659651056 +0000
@@ -343,6 +343,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 `RunsWithRelatedCountsDict` is not assignable to parameter `batch` with type `Mapping[str, int]` in function `WorkflowRunCleanup._accumulate_related_counts` [bad-argument-type]
+ --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:327:73
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]
|
auto-merge was automatically disabled
April 6, 2026 01:11
Head branch was pushed to by a user without write access
288bce1 to
8380263
Compare
Contributor
Pyrefly DiffNo changes detected. |
asukaminato0721
approved these changes
Apr 6, 2026
Contributor
Author
|
@asukaminato0721 Could you please merge this? Thank you. |
HanqingZ
pushed a commit
to HanqingZ/dify
that referenced
this pull request
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RelatedCountsDictTypedDict with keysnode_executions,offloads,app_logs,trigger_logs,pauses,pause_reasons_empty_related_countsreturn type,_format_related_countsparameter, and_record_batch_resultparameterWhy this change
_empty_related_countsconstructs a dict with 6 fixed integer keys, and_format_related_countsaccesses them all by name withcounts['node_executions']etc. The TypedDict makes the contract explicit and lets the type checker catch key typos.Changes
services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py: DefineRelatedCountsDict, update 3 method signaturesTest plan
ruff checkpassesPart of #32863 (
services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py)