Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

fix: Removing items during validation breaks validation #277

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion media/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import util


class ItemNotCachedError(Exception):
pass


class MusicCache(dict):
def __init__(self, db: MusicDatabase):
super().__init__()
Expand Down Expand Up @@ -142,7 +146,7 @@ def item(self):
if self.id in self.lib:
return self.lib[self.id]
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything after the return is automatically an else block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it does no harm to explicitly use an else statement :)

raise ValueError(f"Uncached item of id {self.id}, type {self.type}.")
raise ItemNotCachedError(f"Uncached item of id {self.id}, type {self.type}.")

def to_dict(self):
dict = self.item().to_dict()
Expand Down
12 changes: 11 additions & 1 deletion media/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import time

import variables as var
from media.cache import CachedItemWrapper, get_cached_wrapper_from_dict, get_cached_wrapper_by_id
from media.cache import (CachedItemWrapper, ItemNotCachedError,
get_cached_wrapper_from_dict, get_cached_wrapper_by_id)
from database import Condition
from media.item import ValidationFailedError, PreparationFailedError

Expand Down Expand Up @@ -224,6 +225,15 @@ def _check_valid(self):
self.validating_thread_lock.acquire()
while len(self.pending_items) > 0:
item = self.pending_items.pop()
try:
item.item()
except ItemNotCachedError:
# In some very subtle case, items are removed and freed from
# the playlist and the cache, before validation even starts,
# causes, freed items remain in pending_items.
# Simply ignore these items here.
continue

self.log.debug("playlist: validating %s" % item.format_debug_string())
ver = item.version

Expand Down