Skip to content

Commit

Permalink
Pure Python Set objects were also not marking themselves changed on a…
Browse files Browse the repository at this point in the history
…ddition. This impacted things like zope.index.topic.filter
  • Loading branch information
jamadden committed May 13, 2015
1 parent 332503d commit aa091e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions BTrees/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def _set(self, key, value=None, ifunset=False):
index = self._search(key)
if index < 0:
index = -index - 1
self._p_changed = True
self._keys.insert(index, key)
return True, None
return False, None
Expand Down
26 changes: 26 additions & 0 deletions BTrees/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,32 @@ def register(self, arg):
self.assertTrue(t._p_changed)
self.assertEqual(t, t._p_jar.registered)

def testAddingOneSetsChanged(self):
# A bug in the BTree Set Python implementation once caused
# adding an object not to set _p_changed
t = self._makeOne()
# Note that for the property to actually hold, we have to fake a
# _p_jar and _p_oid
t._p_oid = b'\0\0\0\0\0'
class Jar(object):
def __init__(self):
self._cache = self
self.registered = None

def mru(self, arg):
pass
def readCurrent(self, arg):
pass
def register(self, arg):
self.registered = arg

t._p_jar = Jar()
t.add(0)
self.assertTrue(t._p_changed)
self.assertEqual(t, t._p_jar.registered)

# Whether or not doing `t.add(0)` again would result in
# _p_changed being set depends on whether this is a TreeSet or a plain Set

class ExtendedSetTests(NormalSetTests):

Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
------------------

- Fix _p_changed when removing items from small pure-Python
BTrees/TreeSets. See:
BTrees/TreeSets and when adding to Sets. See:
https://github.com/zopefoundation/BTrees/issues/13


Expand Down

0 comments on commit aa091e6

Please sign in to comment.