Re: [ZODB-Dev] zodb does not save transaction
Laurence Rowe wrote: > > tsmiller wrote: > I have a bookstore that uses the ZODB as its storage. It uses qooxdoo as the client and CherryPy for the server. The server has a 'saveBookById' routine that works 'most' of the time. However, sometimes the transaction.commit() does NOT commit the changes and when I restart my server the changes are lost. > >>> This sounds like you are using mutable data types (like lists or dicts) >>> in >>> the >>> non-persistence aware variants. > >> Christian, thanks for the reply. >> When I save a book I save a dictionary where all of the keys are strings >> and >> all of the values are strings. But what you say makes sense. I keep >> thinking that it must have something to do with the data itself. I will >> check very carefully to make sure that I am not saving anything but >> strings >> in the book record. Thanks. Tom > > The problem is not saving things that are not strings, but modifying a > non persistent object without notifying the parent persistent object > that a change has happened and it needs to be saved. > e.g. > > you have a persistent object (inherits from persistent.Persistent) pobj > > >>> pobj.dict = {} > >>> transaction.commit() > >>> pobj.dict['foo'] = 'bar' > >>> transaction.commit() > >>> print pobj.dict > {'foo': 'bar'} > > #restart your python process > >>> print pobj.dict > {} > > Instead you must either tell zodb the object has changed: > > >>> pobj.dict = {} > >>> transaction.commit() > >>> pobj.dict['foo'] = 'bar' > >>> pbj._p_changed = True # alternatively: pobj.dict = pobj.dict > >>> transaction.commit() > >>> print pobj.dict > {'foo': 'bar'} > > #restart your python process > >>> print pobj.dict > {'foo': 'bar'} > > Or use a persistence aware replacement. > > >>> from persistent.mapping import PersistentMapping > >>> pobj.dict = PersistentMapping() > >>> transaction.commit() > >>> pobj.dict['foo'] = 'bar' > >>> transaction.commit() > >>> print pobj.dict > {'foo': 'bar'} > > #restart your python process > >>> print pobj.dict > {'foo': 'bar'} > > The same principles apply to other mutable non-peristent objects, such > as lists. > > Laurence > > ___ > For more information about ZODB, see the ZODB Wiki: > http://www.zope.org/Wikis/ZODB/ > > ZODB-Dev mailing list - ZODB-Dev@zope.org > http://mail.zope.org/mailman/listinfo/zodb-dev > > Laurence, Thank you and all of you. I understand the principle and right off the bat I do not see why I am breaking it, but I will look hard and long at the roblem. Thank you for giving me a starting point. Tom -- View this message in context: http://www.nabble.com/zodb-does-not-save-transaction-tp17526533p17547540.html Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com. ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org http://mail.zope.org/mailman/listinfo/zodb-dev
Re: [ZODB-Dev] zodb does not save transaction
Christian Theune-2 wrote: > > On Wed, May 28, 2008 at 07:55:19PM -0700, tsmiller wrote: >> >> ZODB list, >> >> I have a bookstore that uses the ZODB as its storage. It uses qooxdoo as >> the client and CherryPy for the server. The server has a 'saveBookById' >> routine that works 'most' of the time. However, sometimes the >> transaction.commit() does NOT commit the changes and when I restart my >> server the changes are lost. > > This sounds like you are using mutable data types (like lists or dicts) in > the > non-persistence aware variants. > > Christian > > -- > Christian Theune · [EMAIL PROTECTED] > gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany > http://gocept.com · tel +49 345 1229889 7 · fax +49 345 1229889 1 > Zope and Plone consulting and development > ___ > For more information about ZODB, see the ZODB Wiki: > http://www.zope.org/Wikis/ZODB/ > > ZODB-Dev mailing list - ZODB-Dev@zope.org > http://mail.zope.org/mailman/listinfo/zodb-dev > > Christian, thanks for the reply. When I save a book I save a dictionary where all of the keys are strings and all of the values are strings. But what you say makes sense. I keep thinking that it must have something to do with the data itself. I will check very carefully to make sure that I am not saving anything but strings in the book record. Thanks. Tom -- View this message in context: http://www.nabble.com/zodb-does-not-save-transaction-tp17526533p17544708.html Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com. ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org http://mail.zope.org/mailman/listinfo/zodb-dev
Re: [ZODB-Dev] zodb does not save transaction
tsmiller wrote at 2008-5-28 19:55 -0700: > ... >I have a bookstore that uses the ZODB as its storage. It uses qooxdoo as >the client and CherryPy for the server. The server has a 'saveBookById' >routine that works 'most' of the time. However, sometimes the >transaction.commit() does NOT commit the changes and when I restart my >server the changes are lost. This looks like a persistency bug. Persistency bugs of this kind happen when a nonpersistent mutable instance is modified in place without that the containing persistent object is told about the change. Then the change is persisted only accidentally (together with another change of the containing persisted object). However, the change is seen inside the connection that did the change -- until the containing persistent object is flushed from the ZODB cache (or a restart happens, of course). -- Dieter ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org http://mail.zope.org/mailman/listinfo/zodb-dev
Re: [ZODB-Dev] zodb does not save transaction
On Wed, May 28, 2008 at 07:55:19PM -0700, tsmiller wrote: > > ZODB list, > > I have a bookstore that uses the ZODB as its storage. It uses qooxdoo as > the client and CherryPy for the server. The server has a 'saveBookById' > routine that works 'most' of the time. However, sometimes the > transaction.commit() does NOT commit the changes and when I restart my > server the changes are lost. This sounds like you are using mutable data types (like lists or dicts) in the non-persistence aware variants. Christian -- Christian Theune · [EMAIL PROTECTED] gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany http://gocept.com · tel +49 345 1229889 7 · fax +49 345 1229889 1 Zope and Plone consulting and development ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org http://mail.zope.org/mailman/listinfo/zodb-dev
[ZODB-Dev] zodb does not save transaction
ZODB list, I have a bookstore that uses the ZODB as its storage. It uses qooxdoo as the client and CherryPy for the server. The server has a 'saveBookById' routine that works 'most' of the time. However, sometimes the transaction.commit() does NOT commit the changes and when I restart my server the changes are lost. My save routine writes a message to a log file each time a book is saved and the log file ALWAYS shows that the book is saved successfully, even when it is not. Following is the relevant code. I am sure the keys (bookNumber and storeNumber ) are correct for each call. Please give me some clues and a place to start looking. Tell me what information you need to help. The ZODB is really nice, but it is also very mysterious. Thanks, Tom ... record, bookNumber and storeNumber are defined previously. and db.dbRoot['books'] is an IOBTree ... record is the book record, bookNumber and storeNumber are both integers. ... record is a regular python dictionary ... the except clause below is never triggered bookBase = db.dbRoot['books'][storeNumber] try: bookBase[bookNumber] = record db.dbRoot['books'][storeNumber] = bookBase transaction.commit() log("saveNewBook " + str(bookNumber) + "\t" + str(record)) log("ADD NEW BOOK SUCCESSFULL" + str(bookNumber)) return json.write( { "status" : "success" , 'book-id' : bookId , 'title': title, 'store-number': storeNumber, 'book-number': bookNumber, 'record': record} ) except: log("ERROR in saveNewBook " + str(bookNumber) + "\t" + str(record)) return json.write( { "status" : "failure" , 'msg' : "Book could not be added."} ) -- View this message in context: http://www.nabble.com/zodb-does-not-save-transaction-tp17526533p17526533.html Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com. ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org http://mail.zope.org/mailman/listinfo/zodb-dev