ComparableVersionedObject.__eq__ reports non-equality if list of changed fields differ
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
oslo.versionedobjects |
Confirmed
|
Medium
|
Unassigned |
Bug Description
Consider this code from the ovo test suite test_objects.py file
def test_comparable
obj1 = MyComparableObj
obj2 = MyComparableObj
obj3 = MyComparableObj
self.assertTru
This all looks fine, and indeed it passes, but now lets reset the list of change fields on obj2 and try that comparison again
obj1 and obj2 should still be treated as equal since all their properties are the same but the test now fails
FAIL: oslo_versionedo
tags: worker-6
-------
Empty attachments:
pythonlogging:''
stderr
stdout
Traceback (most recent call last):
File "oslo_versioned
self.
File "/home/
self.
File "/home/
raise mismatch_error
testtools.
reference = MyComparableObj
actual = MyComparableObj
What is particularly unpleasant is that the result of __repr__ shows that are identical.
Looking at the __eq__ implementation, it calls obj_to_primitive(). This dict it generates includes a list of changed fields and this causes the equality comparison to fail.
The __eq__ implementation should not be affected by the list of changed fields - only the actual field values should affect it.
This has had other nasty side effects too, such as __eq__ method being fragile wrt python hash seed which causes random failures of tests which use object eqality (see https:/
Changed in oslo.versionedobjects: | |
status: | New → Confirmed |
importance: | Undecided → Medium |