[PATCH 3/3] Fix app.status call in log_dict_diff

Lars Wirzenius lars.wirzenius at codethink.co.uk
Wed Oct 23 17:29:41 BST 2013

This bug was triggered by the fix to CachedRepo.resolve_ref and without
this fix, the resolve_ref fix will break the test suite.

The bug is that log_dict_diff calls the status method with an msg
keyword argument that may contain percentage characters. status
interprets the value of msg as a format string, and the percentage
characters trigger formatting to happen.

The fix for that is to not interpolate the value of key and dictA[key]
and dictB[key] into msg before calling status, but letting status
do that. Thus the msg values are changed to reference %(key)s instead
and passing in a value for key as a separate argument. Ditto for
dictA[key] and dictB[key].
 morphlib/util.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/morphlib/util.py b/morphlib/util.py
index 3d9232d..53a9e28 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -177,7 +177,8 @@ def log_dict_diff(app, cur, pre): # pragma: no cover
     dictB = pre
     for key in dictA.keys():
         if key not in dictB:
-            app.status(msg="New environment: %s = %s" % (key, dictA[key]),
+            app.status(msg="New environment: %(key)s = %(value)s",
+                       key=key, value=dictA[key],
         elif dictA[key] != dictB[key]:
             app.status(msg= \
@@ -185,7 +186,8 @@ def log_dict_diff(app, cur, pre): # pragma: no cover
                 % {"key": key, "valA": dictA[key], "valB": dictB[key]})
     for key in dictB.keys():
         if key not in dictA:
-            app.status(msg="Environment removed:  %s = %s" % (key, dictB[key]))
+            app.status(msg="Environment removed:  %(key)s = %(value)s",
+                       key=key, value=dictB[key])
 # This acquired from rdiff-backup which is GPLv2+ and a patch from 2011

More information about the baserock-dev mailing list