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

Commit

Permalink
Fix insert followed by remove in the same transaction. The document w…
Browse files Browse the repository at this point in the history
…as not removed from mongo.
  • Loading branch information
agroszer committed Jun 13, 2013
1 parent 69b999d commit 742401c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,9 @@ CHANGES
0.8.4 (unreleased)
------------------

- Fix insert followed by remove in the same transaction. The document was
not removed from mongo.

- Fix transaction.abort() behaviour for complex objects. _py_type information
is not lost after transaction abort().

Expand Down
10 changes: 6 additions & 4 deletions src/mongopersist/datamanager.py
Expand Up @@ -291,17 +291,19 @@ def insert(self, obj):
def remove(self, obj):
if obj._p_oid is None:
raise ValueError('Object does not have OID.', obj)
# Edge case: The object was just added in this transaction.
if obj in self._inserted_objects:
self._inserted_objects.remove(obj)
return
# If the object is still in the ghost state, let's load it, so that we
# have the state in case we abort the transaction later.
if obj._p_changed is None:
self.setstate(obj)
# Now we remove the object from Mongo.
coll = self.get_collection_from_object(obj)
coll.remove({'_id': obj._p_oid.id})
# Edge case: The object was just added in this transaction.
if obj in self._inserted_objects:
# but it still had to be removed from mongo, because insert
# inserted it just before
self._inserted_objects.remove(obj)
return
self._removed_objects.append(obj)
# Just in case the object was modified before removal, let's remove it
# from the modification list:
Expand Down

0 comments on commit 742401c

Please sign in to comment.