Skip to content

Conversation

@zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Oct 20, 2025

summary

this PR adds a bulk delete endpoint for flow runs

key features

  • filter-based deletion: uses the standard FlowRunFilter for maximum flexibility - delete by IDs, states, tags, or any criteria
  • batch processing: processes flow runs efficiently with proper resource cleanup
  • background log cleanup: schedules log deletion as background tasks to avoid blocking the response

api

  • endpoint: POST /flow_runs/bulk_delete
  • request body:
    • flow_runs: standard FlowRunFilter object (e.g., {"id": {"any_": [id1, id2]}})
    • limit: maximum number of flow runs to delete (1-200, default: 200)
  • response: FlowRunBulkDeleteResponse with deleted flow run IDs
implementation details

processing logic

  • reuses existing FlowRunFilter schema - the same filter used for querying flow runs
  • processes flow runs one at a time with proper concurrency slot cleanup
  • schedules log deletion as background tasks

🤖 Generated with Claude Code

adds a bulk delete endpoint for flow runs using the same filter used by the `POST /filter` read endpoint

### key features

- **filter-based deletion**: uses the standard `FlowRunFilter` for maximum flexibility - delete by IDs, states, tags, or any criteria
- **batch processing**: processes flow runs efficiently with proper resource cleanup
- **background log cleanup**: schedules log deletion as background tasks to avoid blocking the response

### api

- **endpoint**: `POST /flow_runs/bulk_delete`
- **request body**:
  - `flow_runs`: standard `FlowRunFilter` object (e.g., `{"id": {"any_": [id1, id2]}}`)
  - `limit`: maximum number of flow runs to delete (1-200, default: 200)
- **response**: `FlowRunBulkDeleteResponse` with deleted flow run IDs

### implementation

- reuses existing `FlowRunFilter` schema - the same filter used for querying flow runs
- uses hard deletion (unlike cloud's soft deletion)
- properly handles concurrency slot cleanup
- background tasks handle log deletion

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions bot added the enhancement An improvement of an existing feature label Oct 20, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 20, 2025

CodSpeed Performance Report

Merging #19232 will not alter performance

Comparing backport/flow-run-bulk-delete (f98e75f) with main (9bae64b)

Summary

✅ 2 untouched

- test_bulk_delete_by_ids: Tests deletion by specific flow run IDs
- test_bulk_delete_by_tags: Tests deletion by tag filtering
- test_bulk_delete_limit: Tests that the limit parameter is enforced
- test_bulk_delete_validation: Tests parameter validation
- test_bulk_delete_with_concurrency_slots: Tests concurrency slot cleanup

All tests pass ✅

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@zzstoatzz
Copy link
Collaborator Author

Test Results ✅

Added comprehensive test coverage for the bulk delete endpoint:

Test Coverage

  • test_bulk_delete_by_ids: Verifies deletion by specific flow run IDs (create 5, delete 3, verify 2 remain)
  • test_bulk_delete_by_tags: Tests filtering by tags (create tagged/untagged runs, delete only tagged)
  • test_bulk_delete_limit: Ensures the limit parameter is enforced (create 10, limit to 5, verify only 5 deleted)
  • test_bulk_delete_validation: Tests parameter validation (limit too high/low returns 422)
  • test_bulk_delete_with_concurrency_slots: Verifies concurrency slots are released on deletion

Manual Testing

Also created and ran sandbox/test_bulk_delete.py against a live Prefect server to verify end-to-end functionality.

All tests pass:

tests/server/orchestration/api/test_flow_runs.py::TestBulkDeleteFlowRuns::test_bulk_delete_by_ids PASSED
tests/server/orchestration/api/test_flow_runs.py::TestBulkDeleteFlowRuns::test_bulk_delete_by_tags PASSED
tests/server/orchestration/api/test_flow_runs.py::TestBulkDeleteFlowRuns::test_bulk_delete_limit PASSED
tests/server/orchestration/api/test_flow_runs.py::TestBulkDeleteFlowRuns::test_bulk_delete_validation PASSED
tests/server/orchestration/api/test_flow_runs.py::TestBulkDeleteFlowRuns::test_bulk_delete_with_concurrency_slots PASSED

Following project convention - test fixtures don't have type hints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants