Skip to content

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

Open
YB0y wants to merge 2 commits intolanggenius:mainfrom
YB0y:refactor/typed-dict-workflow-run-repo-counts
Open

refactor(api): type workflow run delete/count results with RunsWithRelatedCountsDict TypedDict#34531
YB0y wants to merge 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Pyrefly Diff

No changes detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant