1
0
mirror of https://github.com/azlux/botamusique synced 2024-11-23 13:56:17 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Terry Geng
32191bfd9a
Merge pull request #277 from TerryGeng/uncached
fix: Removing items during validation breaks validation
2021-05-18 17:51:47 +08:00
Terry Geng
55daddb774
fix: Removing items during validation breaks validation
Fix #266.
2021-05-16 23:48:07 +08:00
2 changed files with 16 additions and 2 deletions

View File

@ -14,6 +14,10 @@ import variables as var
import util
class ItemNotCachedError(Exception):
pass
class MusicCache(dict):
def __init__(self, db: MusicDatabase):
super().__init__()
@ -142,7 +146,7 @@ class CachedItemWrapper:
if self.id in self.lib:
return self.lib[self.id]
else:
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()

View File

@ -5,7 +5,8 @@ import random
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
@ -224,6 +225,15 @@ class BasePlaylist(list):
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