X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomtask%2Fdb.py;fp=plomtask%2Fdb.py;h=a47dff15917651940483afe83f41152399bedf7f;hb=fa05073a6ebaf46e8f72bec10a3dc03021ce704c;hp=b2f2142c9c6957c19e90674270a1635082050f59;hpb=99672306cdb97d76d00829b2e491f2df0abcbbd5;p=plomtask diff --git a/plomtask/db.py b/plomtask/db.py index b2f2142..a47dff1 100644 --- a/plomtask/db.py +++ b/plomtask/db.py @@ -250,14 +250,19 @@ class BaseModel(Generic[BaseModelId]): raise HandledException(msg) self.id_ = id_ + def __hash__(self) -> int: + hashable = [self.id_] + [getattr(self, name) for name in self.to_save] + for definition in self.to_save_relations: + attr = getattr(self, definition[2]) + hashable += [tuple(rel.id_ for rel in attr)] + for name in self.to_save_versioned: + hashable += [hash(getattr(self, name))] + return hash(tuple(hashable)) + def __eq__(self, other: object) -> bool: if not isinstance(other, self.__class__): return False - to_hash_me = tuple([self.id_] + - [getattr(self, name) for name in self.to_save]) - to_hash_other = tuple([other.id_] + - [getattr(other, name) for name in other.to_save]) - return hash(to_hash_me) == hash(to_hash_other) + return hash(self) == hash(other) def __lt__(self, other: Any) -> bool: if not isinstance(other, self.__class__):