From: Tomas Babej Date: Sat, 17 Jan 2015 10:51:34 +0000 (+0100) Subject: Task: Clean up default formatting of the attributes as arguments for modify command X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/58921ff492b989ac597f13f7306e8ae4cda15826 Task: Clean up default formatting of the attributes as arguments for modify command In the current version, we were not properly making difference between value which is False when converting to boolean, and proper empty value. Thus user would be unable to save legitimate False-like values into TW, like numeric 0. --- diff --git a/tasklib/task.py b/tasklib/task.py index 6de828f..a0b3c28 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -434,13 +434,21 @@ class Task(TaskResource): def add_field(field): # Add the output of format_field method to args list (defaults to # field:value) - serialized_value = self._serialize(field, self._data[field]) or '' - format_default = lambda: "{0}:{1}".format( - field, - "'{0}'".format(serialized_value) if serialized_value else '' - ) + serialized_value = self._serialize(field, self._data[field]) + + # Empty values should not be enclosed in quotation marks, see + # TW-1510 + if serialized_value is '': + escaped_serialized_value = '' + else: + escaped_serialized_value = "'{0}'".format(serialized_value) + + format_default = lambda: "{0}:{1}".format(field, + escaped_serialized_value) + format_func = getattr(self, 'format_{0}'.format(field), format_default) + args.append(format_func()) # If we're modifying saved task, simply pass on all modified fields