fix(subscriber): await season status saves when approving TV requests#2743
fix(subscriber): await season status saves when approving TV requests#2743dougrathbone wants to merge 1 commit intoseerr-team:developfrom
Conversation
When a TV MediaRequest was approved, child SeasonRequest statuses were updated via forEach without awaiting the save calls, making them fire-and-forget. Any code reading season statuses immediately after approval (notification logic, media status checks) could observe stale PENDING values. The declined path in the same function already used for...of with await correctly. This aligns the approved path to the same pattern. Adds tests for both paths to confirm status changes are persisted to the database before updateParentStatus returns.
📝 WalkthroughWalkthroughThis change adds test coverage for the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing this - the exact same fix was already merged in #2760. Nice to see someone else spotted it too! |
Description
When a TV
MediaRequestis approved,updateParentStatusiterates itsSeasonRequestchildren and marks each oneAPPROVED. The saves were issued viaforEachwithoutawait, making them fire-and-forget. Anything reading season statuses immediately after approval -- notification logic, media status checks -- could observe stalePENDINGvalues.The declined path in the same function already does this correctly using
for...ofwithawait. The approved path was inconsistent with it.Before:
After (matching the pattern used in the declined branch):
AI Disclosure: I used Claude Code to help write the tests. I reviewed and understood all generated code before submitting.
How Has This Been Tested?
Integration tests at
server/subscriber/MediaRequestSubscriber.test.tsusing the real SQLite test database viasetupTestDb().Tests:
updateParentStatus-- persistsAPPROVEDstatus to all childSeasonRequestrows in the database (regression guard for the unawaited save)updateParentStatus-- persistsDECLINEDstatus to all childSeasonRequestrows (regression guard for the already-correct declined path)To reproduce the bug manually:
PUT /api/v1/request/:id/approve.seasons[].status.PENDINGdue to unawaited saves racing with the response.APPROVED.Screenshots / Logs (if applicable)
N/A -- backend-only change with no UI impact.
Checklist:
pnpm buildpnpm i18n:extract(no new UI strings added)