SEP-1705: Add BaseManager.exists() and convert existence checks - #1251
SEP-1705: Add BaseManager.exists() and convert existence checks#1251olucasandrade wants to merge 7 commits into
Conversation
Route existence-by-count and the bespoke TaskHistoryLogManager.exists_for_task helpers through a shared short-circuiting SELECT EXISTS query.
There was a problem hiding this comment.
Pull request overview
This PR introduces a reusable BaseManager.exists() helper for short-circuit existence checks across the FastAPI/SQLModel data layer, then updates a few hot paths (settings override delete, app drain finalize, and task-history log presence checks) to use it instead of count(...) > 0 or a bespoke manager method.
Changes:
- Add
BaseManager.exists()implemented via_filter_query(...)andSELECT EXISTS (...). - Replace select existence checks (
count(...) > 0, app drain finalize) withexists(...). - Remove
TaskHistoryLogManager.exists_for_taskand retarget call sites/tests toTaskHistoryLogManager.exists(session, task_history_id=...).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
app/core/db/crud.py |
Adds BaseManager.exists() using _filter_query and SELECT EXISTS (...). |
app/core/settings_override/api/routes.py |
Switches override-row existence detection from count(...) > 0 to exists(...). |
app/sep/app_drain.py |
Converts the “any running tasks for app” check from count(...) to exists(...). |
app/tasks/crud.py |
Removes TaskHistoryLogManager.exists_for_task and updates related doc references; cleans up now-unused import. |
app/tasks/routes.py |
Updates task history has_logs computation to use TaskHistoryLogManager.exists(...). |
app/tasks/logs/log_reader.py |
Switches chunk-presence detection from exists_for_task to exists(...). |
tests/app/core/db/test_crud.py |
Adds focused unit tests covering BaseManager.exists() behavior and filter handling. |
tests/app/tasks/test_routes.py |
Updates assertions to use TaskHistoryLogManager.exists(...). |
tests/app/tasks/connectivity/test_service.py |
Updates log-row existence assertions to exists(...). |
tests/app/tasks/connectivity/test_routes.py |
Updates log-row existence assertions to exists(...) for HTTP-level tests. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@copilot resolve the merge conflicts in this pull request |
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: olucasandrade <64823667+olucasandrade@users.noreply.github.com>
Resolved in commit |
Summary
BaseManager.exists()that emits a short-circuitingSELECT EXISTS (...)with the same filter signature ascount(), built through_filter_query.count(...)toexists().TaskHistoryLogManager.exists_for_taskand retarget its callers, tests, and docstring cross-references toexists(session, task_history_id=...).Closes / implements SEP-1705. Related: SEP-1689 / PR #1235 review thread; blocks SEP-1707 only by landing first on the same statement.
Tested
NOT_OVERRIDABLEsettings key with no override row and confirm 409 is unchangedChecklist
make test) — targeted gate: 264 passed, 1 skippedmake run-pre-commit) — ran on commitDatabase migrations generated if models changed ((N/A)make makemigrations)User-facing changes documented (README, inline help, UI text)(N/A)Configuration changes documented with examples(N/A)Changelog fragment added under(N/A — internal-only refactor)changelog.d/