Skip to content

refactor(api): type workflow run related counts with RelatedCountsDict TypedDict#34530

Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom
YB0y:refactor/typed-dict-workflow-run-related-counts
Apr 6, 2026
Merged

refactor(api): type workflow run related counts with RelatedCountsDict TypedDict#34530
asukaminato0721 merged 1 commit intolanggenius:mainfrom
YB0y:refactor/typed-dict-workflow-run-related-counts

Conversation

@YB0y
Copy link
Copy Markdown
Contributor

@YB0y YB0y commented Apr 3, 2026

Summary

  • Add RelatedCountsDict TypedDict with keys node_executions, offloads, app_logs, trigger_logs, pauses, pause_reasons
  • Annotate _empty_related_counts return type, _format_related_counts parameter, and _record_batch_result parameter

Why this change

_empty_related_counts constructs a dict with 6 fixed integer keys, and _format_related_counts accesses them all by name with counts['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: Define RelatedCountsDict, update 3 method signatures

Test plan

  • ruff check passes

Part of #32863 (services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py)

@YB0y YB0y requested a review from QuantumGhost as a code owner April 3, 2026 13:01
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Apr 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Pyrefly Diff

base → 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]

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from 478c26c to ea8bf61 Compare April 3, 2026 13:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Pyrefly Diff

base → 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]

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from ea8bf61 to 63a5894 Compare April 3, 2026 13:32
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Pyrefly Diff

base → 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]

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from 63a5894 to df4c636 Compare April 3, 2026 16:21
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Pyrefly Diff

base → 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]

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from df4c636 to ab1eb51 Compare April 3, 2026 16:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Pyrefly Diff

No changes detected.

Comment thread api/services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py Outdated
@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from ab1eb51 to 2d69cf1 Compare April 4, 2026 15:10
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 4, 2026

Pyrefly Diff

No changes detected.

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from 2d69cf1 to 197aaeb Compare April 5, 2026 22:44
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

base → 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]

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from 197aaeb to 288bce1 Compare April 5, 2026 22:47
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

base → 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

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-related-counts branch from 288bce1 to 8380263 Compare April 6, 2026 01:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

Pyrefly Diff

No changes detected.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 6, 2026
@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented Apr 6, 2026

@asukaminato0721 Could you please merge this? Thank you.

@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 6, 2026
Merged via the queue into langgenius:main with commit 5ad906e Apr 6, 2026
27 checks passed
@YB0y YB0y deleted the refactor/typed-dict-workflow-run-related-counts branch April 6, 2026 16:05
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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants