From 38f87923d86a910838cf7a2c7342d0f3d7c75b37 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 28 Dec 2015 00:12:49 +0100 Subject: [PATCH] Song errors are cached only if there isn't any of them --- patacrep/songs/__init__.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index e1b14c05..3745ab9e 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -90,7 +90,7 @@ class Song: # Version format of cached song. Increment this number if we update # information stored in cache. - CACHE_VERSION = 3 + CACHE_VERSION = 4 # List of attributes to cache cached_attributes = [ @@ -98,6 +98,7 @@ class Song: "unprefixed_titles", "cached", "data", + "errors", "lang", "authors", "_filehash", @@ -185,13 +186,19 @@ class Song: def _write_cache(self): """If relevant, write a dumbed down version of self to the cache.""" - if self.use_cache: - cached = {attr: getattr(self, attr) for attr in self.cached_attributes} - pickle.dump( - cached, - open(self.cached_name, 'wb'), - protocol=-1 - ) + if not self.use_cache: + return + if self.errors: + # As errors are exceptions, we cannot cache them because of a Python + # bug. When this bug is fixed, we will cache errors. + # https://bugs.python.org/issue1692335 + return + cached = {attr: getattr(self, attr) for attr in self.cached_attributes} + pickle.dump( + cached, + open(self.cached_name, 'wb'), + protocol=-1 + ) def __str__(self): return str(self.fullpath)