Skip to content

refactor(api): type workflow run delete/count results with RunsWithRelatedCountsDict TypedDict#34531

Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom
YB0y:refactor/typed-dict-workflow-run-repo-counts
Apr 5, 2026
Merged

refactor(api): type workflow run delete/count results with RunsWithRelatedCountsDict TypedDict#34531
asukaminato0721 merged 2 commits intolanggenius:mainfrom
YB0y:refactor/typed-dict-workflow-run-repo-counts

Conversation

@YB0y
Copy link
Copy Markdown
Contributor

@YB0y YB0y commented Apr 3, 2026

Summary

  • Add RunsWithRelatedCountsDict TypedDict with keys runs, node_executions, offloads, app_logs, trigger_logs, pauses, pause_reasons
  • Annotate return types of delete_runs_with_related and count_runs_with_related in both protocol and implementation

Why this change

Both methods return a 7-key integer dict representing counts of deleted/counted workflow runs and their related records. The dict shape is identical across the abstract protocol and its SQLAlchemy implementation, and callers access keys by name. A TypedDict makes the contract explicit at the protocol level.

Changes

  • repositories/api_workflow_run_repository.py: Define RunsWithRelatedCountsDict, update 2 protocol method return types
  • repositories/sqlalchemy_api_workflow_run_repository.py: Import TypedDict, update 2 implementation method return types

Test plan

  • ruff check passes

Part of #32863 (repositories/api_workflow_run_repository.py, repositories/sqlalchemy_api_workflow_run_repository.py)

@YB0y YB0y requested a review from QuantumGhost as a code owner April 3, 2026 13:09
@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:10:51.766135851 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-03 13:10:41.884139977 +0000
@@ -343,6 +343,14 @@
   --> 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 `+=` is not supported between `int` and `object` [unsupported-operation]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:316:29
+ERROR Argument `dict[str, int | object]` is not assignable to parameter `related_counts` with type `dict[str, int] | None` in function `WorkflowRunCleanupMetrics.record_batch` [bad-argument-type]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:335:40
+ERROR Argument `dict[str, int | object]` is not assignable to parameter `related_counts` with type `dict[str, int] | None` in function `WorkflowRunCleanupMetrics.record_batch` [bad-argument-type]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:375:36
+ERROR `RunsWithRelatedCountsDict` is not assignable to attribute `deleted_counts` with type `dict[str, int]` [bad-assignment]
+   --> services/retention/workflow_run/delete_archived_workflow_run.py:100:37
 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-repo-counts branch from 46ff1b9 to d6fc29e Compare April 3, 2026 13:35
@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 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:36:11.758609018 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-03 13:36:02.878624358 +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: (RunsWithRelatedCountsDict) [no-matching-overload]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:304:56
+ERROR No matching overload found for function `dict.__init__` called with arguments: (RunsWithRelatedCountsDict) [no-matching-overload]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:343:50
 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]

@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:38:15.804466229 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-03 13:38:06.884453495 +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: (RunsWithRelatedCountsDict) [no-matching-overload]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:304:56
+ERROR No matching overload found for function `dict.__init__` called with arguments: (RunsWithRelatedCountsDict) [no-matching-overload]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:345:50
 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-repo-counts branch from dbdde17 to bcf0c39 Compare April 3, 2026 13:45
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Pyrefly Diff

No changes detected.

1 similar comment
@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/delete_archived_workflow_run.py Outdated
Comment thread api/services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py Outdated
Comment thread api/services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py Outdated
auto-merge was automatically disabled April 5, 2026 14:14

Head branch was pushed to by a user without write access

@YB0y YB0y force-pushed the refactor/typed-dict-workflow-run-repo-counts branch from 17f5fb0 to 520d7c5 Compare April 5, 2026 14:14
@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 14:15:37.352309671 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-05 14:15:28.524302729 +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 `+=` is not supported between `int` and `object` [unsupported-operation]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:319:29
 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]

@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 14:17:39.168772857 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-05 14:17:30.370803301 +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 `+=` is not supported between `int` and `object` [unsupported-operation]
+   --> services/retention/workflow_run/clear_free_plan_expired_workflow_run_logs.py:319:29
 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-repo-counts branch from 7eab92f to 567227a Compare April 5, 2026 14:51
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

No changes detected.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

No changes detected.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 5, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 5, 2026
Merged via the queue into langgenius:main with commit b71b9f8 Apr 5, 2026
27 checks passed
@YB0y YB0y deleted the refactor/typed-dict-workflow-run-repo-counts branch April 8, 2026 13:35
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
…latedCountsDict TypedDict (langgenius#34531)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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