Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Restore the state of the parent on aborts with persistent subobjects.
Browse files Browse the repository at this point in the history
  • Loading branch information
alga committed Feb 19, 2014
1 parent ff0fc55 commit 558344c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -35,6 +35,9 @@ CHANGES
least 2 replications have been successfully been reported (w=3). It used to
be set to w=1, which blocks until master confirms the write.

- Bug: When a persistent object which is a subobject is modified, on
abort restore the state of the parent object.

- Bug: When a sub-document object is changed and then the main object is
removed, the removed object would re-appear, since the sub-document object
was still registered as changed and caused a write undoing the removal. The
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -11,7 +11,7 @@ def read(*rnames):

setup(
name='mongopersist',
version='0.9.0.dev7',
version='0.9.0.dev8',
author="Stephan Richter",
author_email="stephan.richter@gmail.com",
url='https://github.com/zopefoundation/mongopersist',
Expand Down
1 change: 1 addition & 0 deletions src/mongopersist/datamanager.py
Expand Up @@ -367,6 +367,7 @@ def register(self, obj):
if id(obj) not in self._registered_objects:
self._registered_objects[id(obj)] = obj
if id(obj) not in self._modified_objects:
obj = self._get_doc_object(obj)
self._modified_objects[id(obj)] = obj
self.conflict_handler.on_modified(obj)

Expand Down
30 changes: 30 additions & 0 deletions src/mongopersist/tests/test_datamanager.py
Expand Up @@ -938,6 +938,36 @@ def doctest_MongoDataManager_abort_subobjects():
"""


def doctest_MongoDataManager_abort_persistent_subobjects():
"""MongoDataManager: Abort subobjects that are persistent
Make sure that multiple changes to the sub-object are registered, even if
they are flushed inbetween. (Note that flushing happens often due to
querying.)
>>> foo = Foo('foo')
>>> dm.root['foo'] = foo
>>> foo.bar = Bar('bar')
>>> dm.tpc_finish(None)
Let's now modify bar and flush before aborting.
>>> foo = dm.root['foo']
>>> foo.bar.name = 'bar-modified'
>>> dm.flush()
>>> dm.abort(transaction.get())
The state was reset:
>>> dm.root['foo'].bar.name
u'bar'
"""


def doctest_MongoDataManager_tpc_begin():
r"""MongoDataManager: tpc_begin()
Expand Down

0 comments on commit 558344c

Please sign in to comment.