[Zope3-dev] Re: [Fwd: [Z3d] 562/ 3 Reject "ObjectCopier must copy not reference the object"]

Philipp von Weitershausen philipp at weitershausen.de
Wed Aug 23 08:50:29 EDT 2006


Egon Frerich wrote:
> Hi,
> 
> here I am again.
> 
> On my PC I've changed zope\copypastemove\__init__.py (lines 396 - 403) from
> 
>>>         checkObject(target, new_name, obj)
>>>
>>>         chooser = INameChooser(target)
>>>         new_name = chooser.chooseName(new_name, obj)
>>>
>>>         copy = locationCopy(obj)
>>>         copy.__parent__ = copy.__name__ = None
>>>         notify(ObjectCopiedEvent(copy, obj))
> 
> to
> 
>>>         copy = locationCopy(obj)
>>>         copy.__parent__ = copy.__name__ = None
>>>
>>>         checkObject(target, new_name, copy)
>>>
>>>         chooser = INameChooser(target)
>>>         new_name = chooser.chooseName(new_name, copy)
>>>
>>>         notify(ObjectCopiedEvent(copy, obj))
> 
> The tests passed. The problem 562 is gone.
> 
> Can somebody review this change?

Ever heard of a (unified) diff? Makes it easier to review code changes.
Other than that, it makes sense that the name chooser should be invoked
for the copy, not for the original.

> @Philip:
> I know there should be a test. But I'm not sure how to create the test
> for this complicated issue. Maybe you can do it and I can learn from it.

Or maybe I can give you a few suggestions (see issue transcript) and you
can do it.

> And please have another look at my NameChooser function and give me an
> explanation why you think "his logic in the namechooser seems bogus too"

The way it modifies the object and call itself again etc. just looks
bogus. I don't think name chooser should be able to modify the object
they're choosing a name for. After all, they're just choosing a name.

I think you really want your own object copier if you have a requirement
that obj.name should be unique throught the system. Again, see the issue
transcript.

Philipp


More information about the Zope3-dev mailing list