Skip to content

fix(subscriber): await season status saves when approving TV requests#2743

Open
dougrathbone wants to merge 1 commit intoseerr-team:developfrom
dougrathbone:dougrathbone/fix/season-approval-status
Open

fix(subscriber): await season status saves when approving TV requests#2743
dougrathbone wants to merge 1 commit intoseerr-team:developfrom
dougrathbone:dougrathbone/fix/season-approval-status

Conversation

@dougrathbone
Copy link
Copy Markdown

@dougrathbone dougrathbone commented Mar 22, 2026

Summary

When a TV MediaRequest is approved, updateParentStatus iterates its SeasonRequest children and marks each one APPROVED. The saves were issued via forEach without await, making them fire-and-forget. Anything reading season statuses synchronously after approval -- notification logic, media status checks -- could observe stale PENDING values.

The declined path in the same function already does this correctly using for...of with await (introduced in the declined-request season-reset logic). The approved path was inconsistent with it.

Before:

entity.seasons.forEach((season) => {
  season.status = MediaRequestStatus.APPROVED;
  seasonRequestRepository.save(season); // unawaited
});

After (matching the pattern used in the declined branch):

for (const season of entity.seasons) {
  season.status = MediaRequestStatus.APPROVED;
  await seasonRequestRepository.save(season);
}

Test plan

  • MediaRequestSubscriber.updateParentStatus -- persists APPROVED status to all child SeasonRequests in the database
  • MediaRequestSubscriber.updateParentStatus -- persists DECLINED status to all child SeasonRequests in the database (documents the existing correct behaviour as a regression guard)

Both tests use the real SQLite test database via setupTestDb(), consistent with the project's existing test approach in server/routes/.


AI disclosure: AI was used for code completion. All testing and interaction with the codebase was done manually.

  • I have checked that this PR does not use AI assistance, OR, I have described the use of AI assistance below.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where child season requests weren't receiving status updates when the parent media request was approved or declined.
  • Tests

    • Added comprehensive test coverage for media request status propagation scenarios.

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.
@dougrathbone dougrathbone requested a review from a team as a code owner March 22, 2026 02:31
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 189f08a5-3373-40aa-8b4d-3e02d47f639b

📥 Commits

Reviewing files that changed from the base of the PR and between dbe1fca and 9a4d8de.

📒 Files selected for processing (2)
  • server/subscriber/MediaRequestSubscriber.test.ts
  • server/subscriber/MediaRequestSubscriber.ts

📝 Walkthrough

Walkthrough

This change adds test coverage for the MediaRequestSubscriber and fixes an async handling issue in the subscriber's updateParentStatus method where season request updates were not being properly awaited.

Changes

Cohort / File(s) Summary
Test File Addition
server/subscriber/MediaRequestSubscriber.test.ts
New test file with 111 lines covering MediaRequestSubscriber.updateParentStatus. Includes test database initialization, helper function to create media and season requests, and two test cases validating that child season statuses are correctly updated to match parent status (APPROVED and DECLINED).
Async Flow Fix
server/subscriber/MediaRequestSubscriber.ts
Changed season update loop from non-awaited synchronous forEach to async for...of loop, ensuring each seasonRequestRepository.save() call is properly awaited before proceeding to the next season.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

preview

Suggested reviewers

  • fallenbagel

Poem

🐰 A fix most fine, async'd at last!
Seasons await their fate so vast,
No more forgotten saves that slip,
For loops bring order to the trip! ✨

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically describes the main fix: awaiting season status saves when approving TV requests, which directly addresses the root cause identified in the PR objectives.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant