Skip to content

fix: reset Video record after orphan cleanup#43

Open
dreamcreated wants to merge 1 commit intowindoze95:mainfrom
dreamcreated:fix/orphan-cleanup-reset-video-status
Open

fix: reset Video record after orphan cleanup#43
dreamcreated wants to merge 1 commit intowindoze95:mainfrom
dreamcreated:fix/orphan-cleanup-reset-video-status

Conversation

@dreamcreated
Copy link
Copy Markdown

Problem

Fixes #17

check_and_delete_orphan in app/services/storage.py correctly removes the physical media, preview, and thumbnail files from disk when a video has no remaining active UserVideoRef associations. However, the Video record itself is never updated — status stays "COMPLETE" and file_path still points to the deleted file.

Impact:

  • A new user subscribing to the same channel later will get a new UserVideoRef, but attempting to stream the video returns a 404 ("Video file missing from disk")
  • Auto-download logic skips the video because status == "COMPLETE", so it never re-downloads
  • Users have no direct path to recover the video without manual DB intervention

Fix

After deleting all files from disk, reset the Video record to reflect its actual state:

video.status = "CATALOGED"
video.file_path = None
video.file_size_bytes = 0
await db.commit()

This makes the video eligible for re-download if a new user subscribes to the channel.

Changes

  • app/services/storage.py: Reset video.status, video.file_path, and video.file_size_bytes after orphan deletion; moved db.commit() inside the function (was missing entirely).

When check_and_delete_orphan removes all physical files, it previously
left the Video.status as 'COMPLETE' and file_path populated. This caused
a stale state where:
- New UserVideoRef associations would try to stream a missing file (404)
- Auto-download logic would skip the video because status='COMPLETE'

Fix: after deleting files from disk, reset the Video record:
  video.status = 'CATALOGED'
  video.file_path = None
  video.file_size_bytes = 0

This allows the video to be re-downloaded if a new user subscribes
to the channel.

Fixes windoze95#17
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.

Bug: Orphan cleanup deletes physical file but leaves Video status as COMPLETE

1 participant