[Checkins] SVN: mongopersist/trunk/ - Bug: don't err on missing _py_serial on older states from mongo

Adam Groszer cvs-admin at zope.org
Fri Apr 6 07:32:06 UTC 2012


Log message for revision 124992:
  - Bug: don't err on missing _py_serial on older states from mongo

Changed:
  U   mongopersist/trunk/CHANGES.txt
  U   mongopersist/trunk/src/mongopersist/conflict.py
  U   mongopersist/trunk/src/mongopersist/tests/test_datamanager.py

-=-
Modified: mongopersist/trunk/CHANGES.txt
===================================================================
--- mongopersist/trunk/CHANGES.txt	2012-04-06 06:57:51 UTC (rev 124991)
+++ mongopersist/trunk/CHANGES.txt	2012-04-06 07:32:03 UTC (rev 124992)
@@ -5,13 +5,15 @@
 0.7.1 (2012-04-??)
 ------------------
 
+- Bug: don't err on missing _py_serial on older states from mongo
+
 - Performance: Switched to ``repoze.lru`` (from ``lru``), which is much
   faster.
 
 - Performance: To avoid excessive hash computations, we now use the hash of
   the ``DBRef`` references as cache keys.
 
-- Bug: ``ObjectId`` ids are not guarantted to be unique accross
+- Bug: ``ObjectId`` ids are not guaranteed to be unique across
   collections. Thus they are a bad key for global caches. So we use full
   ``DBRef`` references instead.
 

Modified: mongopersist/trunk/src/mongopersist/conflict.py
===================================================================
--- mongopersist/trunk/src/mongopersist/conflict.py	2012-04-06 06:57:51 UTC (rev 124991)
+++ mongopersist/trunk/src/mongopersist/conflict.py	2012-04-06 07:32:03 UTC (rev 124992)
@@ -84,9 +84,15 @@
             # This should never happen in a real running system.
             return False
         orig_state = orig_state.copy()
-        orig_state.pop(self.field_name)
+        try:
+            orig_state.pop(self.field_name)
+        except KeyError:
+            pass
         new_state = new_state.copy()
-        new_state.pop(self.field_name)
+        try:
+            new_state.pop(self.field_name)
+        except KeyError:
+            pass
         return orig_state == new_state
 
     def resolve(self, obj, orig_doc, cur_doc, new_doc):

Modified: mongopersist/trunk/src/mongopersist/tests/test_datamanager.py
===================================================================
--- mongopersist/trunk/src/mongopersist/tests/test_datamanager.py	2012-04-06 06:57:51 UTC (rev 124991)
+++ mongopersist/trunk/src/mongopersist/tests/test_datamanager.py	2012-04-06 07:32:03 UTC (rev 124992)
@@ -265,6 +265,52 @@
       {u'_id': ObjectId('...'), u'_py_serial': 3, u'name': u'fuh'}
     """
 
+def doctest_MongoDataManager_dump_only_on_real_change_no_py_serial():
+    r"""MongoDataManager: dump(): dump on real change only.
+
+    Quirk: some objects might not have _py_serial in their state
+
+    The data manager only writes data when we actually have a difference in
+    state.
+
+    We have to use a serial conflict handler, otherwise it is hard to check
+    whether data was written.
+
+      >>> dm.conflict_handler = conflict.SimpleSerialConflictHandler(dm)
+
+    Let's now add an object:
+
+      >>> foo = Foo('foo')
+      >>> foo_ref = dm.insert(foo)
+      >>> dm.tpc_finish(None)
+
+      >>> coll = dm._get_collection_from_object(foo)
+      >>> state = coll.find_one({})
+      >>> state
+      {u'_id': ObjectId('...'), u'_py_serial': 1, u'name': u'foo'}
+
+      >>> del state['_py_serial']
+      >>> coll.save(state)
+      ObjectId('...')
+
+      >>> coll.find_one({})
+      {u'_id': ObjectId('...'), u'name': u'foo'}
+
+    So the original state is in. Let's now modify an object:
+
+      >>> foo = dm.load(foo_ref)
+      >>> foo.name = 'Foo'
+      >>> foo._p_changed
+      True
+      >>> dm.tpc_finish(None)
+
+    _py_serial gets added silently, without an exception
+
+      >>> coll.find_one({})
+      {u'_id': ObjectId('...'), u'_py_serial': 1, u'name': u'Foo'}
+
+    """
+
 def doctest_MongoDataManager_flush():
     r"""MongoDataManager: flush()
 



More information about the checkins mailing list