[Zope] How to set an object's last modification time

Gabriel Genellina gagenellina at softlab.com.ar
Mon Aug 8 23:14:06 EDT 2005


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 



More information about the Zope mailing list