home · contact · privacy
Enhance BaseModel comparisons by hashing versioned and relations attributes.
[plomtask] / plomtask / versioned_attributes.py
index d3c364942e3d76edf0eb9618df8366866c603709..cbd1c8e348a9230b10176d55b4b6a490fe11ff33 100644 (file)
@@ -19,6 +19,12 @@ class VersionedAttribute:
         self.default = default
         self.history: dict[str, str | float] = {}
 
+    def __hash__(self) -> int:
+        history_tuples = tuple((k, v) for k, v in self.history.items())
+        hashable = (self.parent.id_, self.table_name, self.default,
+                    history_tuples)
+        return hash(hashable)
+
     @property
     def _newest_timestamp(self) -> str:
         """Return most recent timestamp."""