Commit c4d7b10e authored by Guoshuai Li's avatar Guoshuai Li
Browse files

Fix the object is unhashable when inheriting the class

"ComparableVersionedObject"

In python3, A class that overrides __eq__() and does not define
"__hash__()" will have its __hash__() implicitly set to None.
This will cause the set method to unhashable failed.
https://docs.python.org/3/reference/datamodel.html#object.__hash__

Change-Id: I21685303e9bd233241b7b4216e3feb7bdaecc0a4
Closes-Bug: #1687592
parent dcb1c059
......@@ -706,6 +706,9 @@ class ComparableVersionedObject(object):
return self.obj_to_primitive() == obj.obj_to_primitive()
return NotImplemented
def __hash__(self):
return super(ComparableVersionedObject, self).__hash__()
def __ne__(self, obj):
if hasattr(obj, 'obj_to_primitive'):
return self.obj_to_primitive() != obj.obj_to_primitive()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment