Martin Aspeli wrote:
> Jens Vagelpohl wrote:
> My concern is just that we need a robust solution that doesn't put too
> much onus on the end developer. If I have to do this it's pretty
> horrendous:
>  >>> mtool = getUtility(IMembershipTool)
>  >>> mtool = mtool.__of__(context)
>  >>> # now use mtool
> especially since the errors I get will likely be confusing. I have
> learned the hard way that having to understand how acquisition interacts
> with your code fully can be painful, and that sometimes the Zope2/Zope3
> divide still forces this on developers. In this case, we need to make it
> as hard as possible to make mistakes, or the learning curve will just
> shoot up again.
> In fact, I'm not quite sure I understand the full extent of the problem
> here, which is why I'm not being more pro-active in offering suggestions.
> Now, I assume we still create the tool objects as
> portal['portal_membership'] or whatever, i.e. they are still
> SimpleItem's or whatever, so they still have acquisition mixed in.
> Presumably, they should also have an aq_parent always, no?
> Then, I assume that on portal setup, we do
> registerUtility(provides=IMembershipTool,
> component=portal.portal_membership) - that is, we are telling the
> persistent local utility registry that we are using the same physical
> object (in the ZODB), rather than giving it a factory from which to
> create its own object.
> This is what leads to believe there ought to be an aq_parent by
> containment, but I guess I may be wrong?

Yep, you are wrong ;)

A sample session from my local zopectl debug:

>>> from Products.CMFPlone.interfaces import ITranslationServiceTool
>>> from zope.component import getUtility

>>> getUtility(ITranslationServiceTool, context=app.test)
<TranslationServiceTool at translation_service>

>>> getUtility(ITranslationServiceTool, context=app.test).aq_parent
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: aq_parent

>>> from Products.CMFCore.utils import getToolByName
>>> getToolByName(app.test, 'translation_service')
<TranslationServiceTool at /test/translation_service>

>>> getToolByName(app.test, 'translation_service').aq_chain
[<TranslationServiceTool at /test/translation_service>, <PloneSite at
/test>, <Application at >]

You currently don't get any Acquisition context for utilities if you
don't wrap them explicitly:

>>> getUtility(ITranslationServiceTool,
[<TranslationServiceTool at /test/translation_service>, <PloneSite at
/test>, <Application at >]


Zope-CMF maillist  -

See for bug reports and feature requests

Reply via email to