fix: apply timeout parameter to all aiohttp sessions in db_calls.py (#4) #41
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-card-creation#41
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-card-creation#4"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #4
Summary
Every async DB function in
db_calls.pyaccepted atimeoutparameter but never forwarded it toaiohttp, so scripts would hang indefinitely if the API became unresponsive.Fixed by passing
aiohttp.ClientTimeout(total=timeout)toaiohttp.ClientSession()in all six functions:db_geturl_getdb_patchdb_postdb_putdb_deleteFiles Changed
db_calls.pyTest Results
No test suite in this repo. Change verified by code review — each
ClientSessionconstructor now receives the timeout object.Other observations
The linter (ruff/black) auto-reformatted some f-string quote styles in the same file on save. Those cosmetic changes are included in the diff but do not affect behaviour.
Review: fix: apply timeout parameter to all aiohttp sessions in db_calls.py
LGTM — ready to merge.
What's correct
The fix is mechanically sound and complete. All six async functions (
db_get,url_get,db_patch,db_post,db_put,db_delete) now constructaiohttp.ClientTimeout(total=timeout)and pass it intoClientSession. Usingtotal=is the right choice — it caps the entire request lifecycle (connect + read), which is the expected behaviour for a general-purpose hang guard.The cosmetic f-string quote reformats (ruff/black normalisation) are pure style with no behavioural effect.
Minor observations (no action required)
db_deletestill hastimeout=3without a type annotation (pre-existing). Harmless —ClientTimeout(total=3)works fine.db_post,db_put,db_patch). For large payload POSTs callers can already override it; the default may feel tight but that's a pre-existing design decision, not introduced here.AUTH_TOKENbearer token is hardcoded on line 7 — pre-existing, not in scope for this PR.Verdict
Correct fix, complete coverage across all six functions, no regressions introduced.
AI Code Review
Files Reviewed
db_calls.py(modified)Findings
Correctness
db_get,url_get,db_patch,db_post,db_put,db_delete) now passaiohttp.ClientTimeout(total=timeout)toaiohttp.ClientSession(). This is the proper aiohttp API for session-level timeouts and will prevent indefinite hangs.timeoutparameter was already present in all six function signatures with a default of3seconds; the fix simply closes the gap between the declared interface and the actual behavior.url_getcorrectly omitsheaders=AUTH_TOKENsince it is a generic URL fetcher, not a DB call. The timeout-only session construction there is appropriate.Security
AUTH_TOKEN = {"Authorization": "Bearer Tp3aO3jhYve5NJF1IqOmJTmk"}). This should be moved to an environment variable or secrets file and excluded from version control. This is not introduced by this PR but is worth addressing separately.Style & Conventions
db_deletestill has an untypedtimeout=3parameter (no: intannotation) — this is pre-existing and out of scope, but worth cleaning up in a follow-up.Suggestions
connect_timeoutin addition tototaltimeout viaaiohttp.ClientTimeout(total=timeout, connect=timeout)if fast-fail on connection refusal is desired.totalalone covers the full request lifecycle but a separate connect timeout gives more granular control. Not required for correctness.Verdict: APPROVED
The fix is correct, targeted, and complete. Every
ClientSessionconstructor now receives the timeout object, resolving the hang-on-unresponsive-API issue described in #4. The cosmetic f-string changes are harmless. No blocking issues introduced.Automated review by Claude PR Reviewer
Approved for merge — timeout parameter now correctly forwarded to aiohttp ClientSession in all six functions.