From: Tomas Babej Date: Sun, 28 Dec 2014 00:53:26 +0000 (+0100) Subject: Task: Make a dict.copy() for _original_data X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/549524410137e15cd2ffcb91937c04c18d996ef7?ds=sidebyside Task: Make a dict.copy() for _original_data --- diff --git a/tasklib/task.py b/tasklib/task.py index 3860f8e..44c6965 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -29,7 +29,9 @@ 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): hydrate_func = getattr(self, 'deserialize_{0}'.format(key), @@ -276,7 +278,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):