diff piecrust/appconfig.py @ 948:6c445771a8dc

internal: Fix caching issues with config variants. Before, changing config variant values could incorrectly re-use a previously cached config as long as there were the same number of variants. Now we build a stricter cache hash based on the actual values.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 05 Oct 2017 00:26:25 -0700
parents c0cbcd4752f0
children 45ad976712ec
line wrap: on
line diff
--- a/piecrust/appconfig.py	Thu Oct 05 00:25:10 2017 -0700
+++ b/piecrust/appconfig.py	Thu Oct 05 00:26:25 2017 -0700
@@ -45,6 +45,7 @@
         self._path = path
         self._theme_path = theme_path
         self._cache = cache or NullCache()
+        self._cache_hash_mod = ''
         self._custom_paths = []
         self._post_fixups = []
         self.theme_config = theme_config
@@ -74,6 +75,7 @@
             set_dict_value(config, path, value)
 
         self._post_fixups.append(_fixup)
+        self._cache_hash_mod += '&val[%s=%s]' % (path, repr(value))
 
     def setAll(self, values, validate=False):
         # Override base class implementation
@@ -102,8 +104,8 @@
                 APP_VERSION, CACHE_VERSION)).encode('utf8'))
         for p in paths:
             cache_key_hash.update(("&path=%s" % p).encode('utf8'))
-        cache_key_hash.update(
-            ("&fixups=%d" % len(self._post_fixups)).encode('utf8'))
+        if self._cache_hash_mod:
+            cache_key_hash.update(self._cache_hash_mod.encode('utf8'))
         cache_key = cache_key_hash.hexdigest()
 
         # Check the cache for a valid version.