[Zope] Problems with tokens disappearing

Jay, Dylan djay@avaya.com
Wed, 4 Jul 2001 10:34:19 +1000


> -----Original Message-----
> From: Dieter Maurer [mailto:dieter@handshake.de]
> Sent: Tuesday, 3 July 2001 4:43 AM
> To: Jay, Dylan
> Cc: 'zope@zope.org'
> Subject: Re: [Zope] Problems with tokens disappearing
> 
> 
> Jay, Dylan writes:
>  > I'm getting this really weird problem with tokens.
>  > I have a tokens property of a ZClass (was also happening 
> with a Folder)
>  > called Members.
>  > 
>  > I add a new item to this list via a python script using
>  > context.Members.append(newitem)
> You are working around Zope's persistence machinery when you
> work like this:
> 
>   A persistent object is able to detect assignments to its
>   attributes. However, it is unable to detect modifications
>   of the attribute value itself without an assignment.
> 
>   In your case, you modify the attribute "Members" without
>   assigning a new value to it.
>   These modifications are not recognized by the persistence
>   machinery. It is very likely that they are lost
>   when the object is flushed from the cache.
> 
> Always use the published API to modify Zope objects.
> Do not use internal knowledge, as it may have strange
> side effects (as in your case) and may break in
> the future (I hope, that DC will change the lists into
> tuples; then properties will no longer have an "append").

If there was a published API. The documentation is all over the place.

Now I have a different problem. My ZClass python script method now looks
like this

if username not in context.Members:
  context.Members.append(username)
  new_members = context.Members
  context.propertysheets.Membership.manage_changeProperties(Members =
new_members)
  return 1
return 0

The problem is that this changes the properties of all the objects not just
the one I'm interested in. It's as if "context" is the class not the
instance.