From 2f50a72c1d1400edddd58ad654611422c92d852a Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 28 Dec 2014 03:15:47 +0100 Subject: [PATCH] Task: Make uuid equality more restrictive for unsaved tasks --- tasklib/task.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tasklib/task.py b/tasklib/task.py index 8fe1e1b..1fa3faa 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -122,10 +122,21 @@ class Task(TaskResource): return self['description'] def __eq__(self, other): - return self['uuid'] == other['uuid'] + if self['uuid'] and other['uuid']: + # For saved Tasks, just define equality by equality of uuids + return self['uuid'] == other['uuid'] + else: + # If the tasks are not saved, compare the actual instances + return id(self) == id(other) + def __hash__(self): - return self['uuid'].__hash__() + if self['uuid']: + # For saved Tasks, just define equality by equality of uuids + return self['uuid'].__hash__() + else: + # If the tasks are not saved, return hash of instance id + return id(self).__hash__() @property def _modified_fields(self): -- 2.39.2