Re: Bug in Archetypes constructor

Max M <[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.devel
Message-ID <[email protected]>
Max M wrote:

> My problem is that I cannot find where in the source to look for this. 
> Would anybody give me a pointer to where/how the archetypes factory 
> method is created, so that I can debug further?

Nevermind. I found it here "Plone-2.1.2\Archetypes\ClassGen.py":


def generateCtor(name, module):
     # self is a App.FactoryDispater, Destination() is the real folder
     ctor = """
def add%(name)s(self, id, **kwargs):
     obj = %(name)s(id)
     self._setObject(id, obj)
     obj = self._getOb(id)
     obj.initializeArchetype(**kwargs)
     return obj.getId()
""" % {'name' : name}
     exec ctor in module.__dict__
     return getattr(module, "add%s" % name)

I see that the problem is here:

     obj = %(name)s(id)
     self._setObject(id, obj)

Which should probably read:

     obj = %(name)s(id)
     id = obj.getId()
     self._setObject(id, obj)

Then it would take into account if the id was changed by the __init__ 
method.

As the id *must* be passed to the init method, it really should have 
this behaviour.

I quickly tested the change and it didn't break Plone.

Does anybody else agree that the previous behaviour was a bug and should 
be fixed?


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.