Skip to content

fix: prevent crash when removing media from null Jellyfin collection#2510

Merged
enoch85 merged 2 commits into
mainfrom
fix/jellyfin-remove-from-null-collection
Mar 24, 2026
Merged

fix: prevent crash when removing media from null Jellyfin collection#2510
enoch85 merged 2 commits into
mainfrom
fix/jellyfin-remove-from-null-collection

Conversation

@enoch85

@enoch85 enoch85 commented Mar 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Guard the Jellyfin removeFromCollection API call when mediaServerId is null (collection doesn't exist on the media server)
  • Move DB cleanup (CollectionMedia deletion + log record) outside the inner try block so it always executes, even if the API call fails
  • Update removeChildFromCollection parameter type to string | null for type accuracy

Root cause

When a Jellyfin collection doesn't exist (auto-deleted when empty, or never created because "custom collection" is unchecked), checkAutomaticMediaServerLink correctly sets mediaServerId = null. But removeChildFromCollection passes this null straight to the Jellyfin SDK, which throws RequiredError. Since the DB cleanup was in the same try block as the API call, items became permanently stuck — every re-run hit the same error for the same items.

Test plan

  • All 500 existing tests pass
  • Verify with Jellyfin: create a rule, run it, change conditions, re-run — items that no longer match should be removed from the Maintainerr collection without errors
  • Verify items are correctly removed from the Jellyfin media server collection when one exists

Closes #2509

@enoch85 enoch85 requested a review from ydkmlt84 as a code owner March 21, 2026 00:01
When a Jellyfin media server collection doesn't exist (e.g. auto-deleted
when empty), removeChildFromCollection would pass null as collectionId
to the Jellyfin SDK, which throws RequiredError. The DB cleanup was also
in the same try block, so items became permanently stuck.

Guard the API call on non-null mediaServerId and always run DB cleanup.

Closes #2509
@enoch85 enoch85 force-pushed the fix/jellyfin-remove-from-null-collection branch from 7c4947d to a32015a Compare March 21, 2026 00:02
enoch85 added a commit that referenced this pull request Mar 21, 2026
PR #2510 - fix: prevent crash when removing media from null Jellyfin collection
- Guard removeFromCollection API call when mediaServerId is null
- Move DB cleanup outside inner try block so items are always cleaned up
- Update parameter type to string | null for type accuracy
@enoch85 enoch85 self-assigned this Mar 21, 2026
Apply null-guard for mediaServerId to main's batch
removeChildrenFromCollection method, preserving the fix
from #2510 while adopting the batch API from #2494.
@enoch85 enoch85 merged commit b87d29e into main Mar 24, 2026
11 checks passed
@enoch85 enoch85 deleted the fix/jellyfin-remove-from-null-collection branch March 24, 2026 21:34
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed to remove X from collection null

1 participant