tests.properties.PropertyKindsTest.test_pickle_events fails
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
Fix Released
|
High
|
Thomas Herve |
Bug Description
As of r269, the test suite fails in the test_pickle_event test.
FAIL: test_pickle_events (tests.
---
Traceback (most recent call last):
File "/home/
result = test_method()
File "/home/
AssertionError: [] != [(<storm.
The test in question creates a class with two Pickle() columns. Using a bit of printf debugging, I noticed that the _start_tracking() was being called for each of the two variables, but only one "flush" event handler ended up being attached.
The following example demonstrates why this is so:
>>> class Foo(object):
... def method(self): pass
... def __eq__(self, other): return True
... def __hash__(self): return 0
...
>>> foo1 = Foo()
>>> foo2 = Foo()
>>> hash(foo1.method) == hash(foo2.method)
True
>>> foo1.method == foo2.method
True
>>>
In the test, both columns contained empty lists as their values. PickleVariable implements __hash__() and __eq__() such that if the values are equal, then they are equal and have the same hash (even if the value is unhashable ...).
So to safely use variable methods as event handlers, those variable classes should implement __hash__ and __eq__ based on object identity (which is the only sane way that you can implement hash() for *mutable* objects). I am not sure what the ramifications are for other bits of code though ...
Related branches
- Gustavo Niemeyer: Approve
- James Henstridge: Approve
Changed in storm: | |
importance: | Undecided → High |
status: | New → Confirmed |
Changed in storm: | |
assignee: | nobody → therve |
Changed in storm: | |
status: | Confirmed → Fix Committed |
Changed in storm: | |
status: | Fix Committed → Fix Released |
Looking further, having any variable types be hashable seems broken. Consider:
>>> from storm.variables import IntVariable
>>> v = IntVariable(42)
>>> s = set([v])
>>> v in s
True
>>> v.set(43)
>>> v in s
False
There seems to be a lot of code that depends on hashability and equality checks for variables, so I am not sure how this should be handled.
Speaking with Thomas on IRC, it seems that this test passed for him. This appears to be due to differences in set iteration order on 32 bit vs. 64 bit (so I guess I was lucky to notice this ...).