[ZODB-Dev] Change in a mutable object(list) not being recognized by ZODB
Marius Gedminas
marius at gedmin.as
Sat Apr 24 09:31:04 EDT 2010
On Sat, Apr 24, 2010 at 02:52:40PM +0530, rohit wrote:
> I have a situation wherein a change made to an attribute(a list) of a ZODB
> obj, is not being recognized. I have set the _p_changed = 1.
I do not see that in your code.
> But still the ZODB doesnt recognize the change. On debugging i realised that
> the obj has the change and then i do a transaction.commit() and close the
> database. But on reaccessing the database i realise that the change hasnt
> been registered.
> Could someone please help me out on this one
You use a lot of nested non-persistent mutable objects (i.e. dicts).
Please be aware that if you modify any of them, you need to find the
containing *persistent* object and set its _p_changed to True.
Your life would be much easier if you used PersistentDict and
PersistentList instead of the builtin classes.
> The code is ::::
> s=open_zodb()
> root=s[0]
> if not root.has_key("Clubs"):
> root["Clubs"] = {}
> ClubRoot=root["Clubs"]
> if not root.has_key("Managers"):
> root["Managers"] = {}
> ManagerRoot=root["Managers"]
> if not root.has_key("Players"):
> root["Players"]={}
> PlayerRoot=root["Players"]
> if not root.has_key("Count"):
> root["Count"] = {}
> CountRoot=root["Count"]
>
>
> club=findclubsbyname(ClubRoot, 'MI')
>
>
>
> print club.Players
> list=addplayers(PlayerRoot, CountRoot, "b", 99, 100)
> PlayerRoot=list[1]
> CountRoot=list[0]
> player=findplayerbyname(PlayerRoot, "b")
> player.Club=club
> playerset=[]
> playerset.append(player)
> playerset.append(player)
> #club.Players.append(player)
> club.makeclubplayerassociation(playerset)
> ClubRoot[club.ClubID]=club
>
> root['Players']=PlayerRoot
> root['Clubs']=ClubRoot
>
> transaction.commit()
> close_zodb(s)
>
>
> //open_zodb() is a function which just opens connection to the databse.
> findclubsbyname returns a club object .
> addplayers is a function which adds a player and returns PlayerRoot and
> CountRoot
> findplayerbyname returns a player object
>
> every club object has an attribte Players which is a list.
Marius Gedminas
--
No proper program contains an indication which as an operator-applied
occurrence identifies an operator-defining occurrence which as an
indication-applied occurrence identifies an indication-defining occurrence
different from the one identified by the given indication as an
indication-applied occurrence.
-- ALGOL 68 Report
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20100424/b713cf27/attachment.bin
More information about the ZODB-Dev
mailing list