X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/blobdiff_plain/3c4a436d69fb02fca34be8f0189780d33ddbfe85..bd3efb6ceee683f9575fb40c4ec9cf730e894939:/tasklib/task.py?ds=sidebyside diff --git a/tasklib/task.py b/tasklib/task.py index 3860f8e..096f656 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -29,9 +29,19 @@ class TaskResource(object): def _load_data(self, data): self._data = data - self._original_data = data + # We need to use a copy for original data, so that changes + # are not propagated + self._original_data = data.copy() def __getitem__(self, key): + # This is a workaround to make TaskResource non-iterable + # over simple index-based iteration + try: + int(key) + raise StopIteration + except ValueError: + pass + hydrate_func = getattr(self, 'deserialize_{0}'.format(key), lambda x: x) return hydrate_func(self._data.get(key)) @@ -276,7 +286,10 @@ class Task(TaskResource): self._original_data.update(to_update) else: self._data = new_data - self._original_data = new_data + # We need to create a clone for original_data though + # Shallow copy is alright, since data dict uses only + # primitive data types + self._original_data = new_data.copy() class TaskFilter(object):