diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 6bbb19ddaf..cd0fee3c3a 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -972,6 +972,7 @@ class GridView(QListView): cache_valid = None else: # A cover is in the cache. Check whether it is up to date. + # Note that if tcdata is not None then it is already a PIL image. has_cover, tcdata, timestamp = db.new_api.cover_or_cache(book_id, timestamp, as_what='pil_image') if has_cover: @@ -1012,12 +1013,6 @@ class GridView(QListView): if cover_tuple.has_cover: # cdata contains either the resized thumbnail, the full cover.jpg # rendered as a PIL image, or None if cover.jpg isn't valid - if cdata.getbbox() is None and cover_tuple.cache_valid: - # Something wrong with the cover data in the cache. Remove it - # from the cache and queue it to render again. - tc.invalidate((book_id,)) - self.render_queue.put(book_id) - return None if not cover_tuple.cache_valid: # The cover isn't in the cache, is stale, or isn't a valid # image. We might have the image from cover.jpg, in which case @@ -1052,6 +1047,20 @@ class GridView(QListView): # The cover data isn't valid. Remove it from the cache tc.invalidate((book_id,)) else: + # Test to see if there is something wrong with the cover data in + # the cache. If so, remove it from the cache and queue it to + # render again. It isn't clear that this can ever happen. One + # possibility is if different versions of calibre are used + # interchangeably. + def getbbox(img): + try: + return img.getbbox() + except Exception: + return None + if getbbox(cdata) is None: + tc.invalidate((book_id,)) + self.render_queue.put(book_id) + return None # The data from the cover cache is valid and is already a thumb. thumb = cdata else: