How to set an object's last modification time
Hello I want to set an object's last modification time to match a certain date. I see that this comes from the _p_mtime attribute and in cPersistence.c it is derived from _p_serial. But when I try to set explicitely _p_serial, there is a ConflictError: ZODB.POSException.ConflictError: database conflict error (oid 0x104a, serial this txn started with 0x035cfc6333333333 2005-05-01 10:11:12.000000, serial currently committed 0x035f10fe1d242e66 2005-08-03 02:38:06.830000) Writting _p_serial used to work fine at least until Zope 2.6.x (http://mail.zope.org/pipermail/zope-dev/2000-March/004020.html) Now I'm using Zope 2.7.7. Maybe I should not be playing with _p_serial, but how can I set the object's last modification time? I want it to be in sync with an external representation (stored in CVS). This is a test script: import Zope from Acquisition import aq_base from ZODB.TimeStamp import TimeStamp from OFS.Folder import Folder from DateTime import DateTime Zope.configure('..\etc\zope.conf') root = Zope.app() # create a test folder, if it does not exist if not 'test' in root.objectIds(): print 'Creating test folder' test = Folder(id='test') root._setObject('test',Folder(id='test')) get_transaction().commit() # I want to change its last-modification-time target = aq_base(root.test) print 'Test folder: %s _p_serial=%s _p_mtime=%s b_m_t=%s' % (target.id, target._p_serial, DateTime(target._p_mtime), target.bobobase_modification_time()) ts = TimeStamp(2005,5,1,10,11,12) # a sample timestamp target._p_serial = repr(ts) target._p_changed = 1 get_transaction().commit() print 'target._p_serial modified OK' print 'Test folder: %s _p_serial=%s _p_mtime=%s b_m_t=%s' % (target.id, target._p_serial, DateTime(target._p_mtime), target.bobobase_modification_time()) #output: #Test folder: test _p_serial=_รพ$.f _p_mtime=2005/08/02 23:38:06.830 GMT-3 b_m_t=2005/08/02 23:38:06.830 GMT-3 #Traceback (most recent call last): # File "C:\Prog\Zope\Questor\bin\testserial.py", line 22, in ? # get_transaction().commit() # File "C:\Prog\Zope\ZopeServer\lib\python\ZODB\Transaction.py", line 241, in commit # ncommitted += self._commit_objects(objects) # File "C:\Prog\Zope\ZopeServer\lib\python\ZODB\Transaction.py", line 356, in _commit_objects # jar.commit(o, self) # File "C:\Prog\Zope\ZopeServer\lib\python\ZODB\Connection.py", line 454, in commit # s=dbstore(oid,serial,p,version,transaction) # File "C:\Prog\Zope\ZopeServer\lib\python\ZODB\FileStorage.py", line 782, in store # serials=(oserial, serial)) #ZODB.POSException.ConflictError: database conflict error (oid 0x104a, serial this txn started with 0x035cfc6333333333 2005-05-01 10:11:12.000000, serial currently committed 0x035f10fe1d242e66 2005-08-03 02:38:06.830000) Gabriel Genellina Softlab SRL
On 9 Aug 2005, at 04:14, Gabriel Genellina wrote:
Maybe I should not be playing with _p_serial, but how can I set the object's last modification time? I want it to be in sync with an external representation (stored in CVS).
Set your very own attribute on the object that holds the modification time, and modify it at will. jens
On 9 Aug 2005, at 04:14, Gabriel Genellina wrote:
Maybe I should not be playing with _p_serial,
Correct, you should not be. All _p_ attributes are reserved for use by the ZODB and applications should never mess with them.
but how can I set the object's last modification time? I want it to be in sync with an external representation (stored in CVS).
Set your very own attribute on the object that holds the modification time, and modify it at will.
What Jens said. -PW
At Tuesday 9/8/2005 16:25, Paul Winkler wrote:
Maybe I should not be playing with _p_serial,
Correct, you should not be. All _p_ attributes are reserved for use by the ZODB and applications should never mess with them.
but how can I set the object's last modification time? I want it to be in sync with an external representation (stored in CVS).
Set your very own attribute on the object that holds the modification time, and modify it at will.
But I need to track the modification time of *all* objects (folders, zpt, python scripts, instances of third-party installed products...). I go back and forth from FileStorage to a filesystem representation (using APE) which is under CVS control. Fortunately I've found a way to successfully modify _p_serial: just ignore the (fictitious) conflict. In fact, there is no real conflict since no data has been modified (and no other thread is running), just the timestamp was changed. def ignoreConflict(self, oid, committedSerial, oldSerial, newpickle, committedData=''): self._serial = oldSerial return newpickle from ZODB.FileStorage import FileStorage FileStorage.tryToResolveConflict = ignoreConflict Of course this script is run offline, with a single user accessing the database, and it works for this specific situation because I know there is no real conflict. Gabriel Genellina Softlab SRL
participants (3)
-
Gabriel Genellina -
Jens Vagelpohl -
Paul Winkler