[Zope] Altering product instance changes all instances!

Edd Dumbill edd@usefulinc.com
Mon, 1 Nov 1999 17:40:50 +0000


On Mon, Nov 01, 1999 at 11:52:20AM -0500, Michel Pelletier wrote:
> Edd Dumbill wrote:
> > 
> > Hi
> > 
> > For my SiteSummary [1] product, I have a default image that is stored as a
> > subobject in my ZClass.
> > 
> > An instance of the product can upload a new image to replace it.
> > 
> > Unfortunately that ends up replacing the image in _all_ instances of the
> > product.
> > 
> > This is not the desired behavior!
> 
> But it is probably the correcy behavior. 

Yes, I figured so

> It sounds like maybe you want your object to be an ObjectManager, and
> contain your Image.

My object subclasses ObjectManager already.  The only way I figure to
get round this is to add to the constructor some code which clones the
Image in the class and adds it to the object itself.  I am dubious as to
whether I can achieve this in DTML -- it's looking like I need an
external method to achieve it.

> I suppose the 'right' thing would be for each
> instance to set an instance attribute when they are instanciated, but
> you can't do that, because you can't set attributes from DTML, it would
> violate security.  You *can* do it from an external method, but that
> might be hairy..hmm.

The 'right' thing happens to properties.  What I guess I wanted was to
be able to add objects in as properties.  But of course this is only
possible for a ZClass that subclasses ObjectManager, so there won't be
anything in the existing Zope interfaces to enable me to do that.

> You might be stretching ZClasses farther than they are capable of going,
> at this point.

:-) I think I might.

>  It might be desireable for us to come up with some way
> for instances to change their attributes, but this is typically not done
> from DTML, DTML is expressly designed not to allow you to 'change'
> objects without using a specific API that that object provides, in
> Python, for the DTML programmer.

I can conceive of a need for ZClasses which subclass ObjectManager to
come "pre-loaded" with objects, kind of like a default population. As I
said above, I guess I can achieve this by putting them in the class and
then cloning them as part of the constructor.

> -Michel

Thanks for your very helpful response.  I'll now look into getting my
constructor to do some cloning.

-- Edd