getUtility(ICatalog) fails with ComponentLookupError

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

getUtility(ICatalog) fails with ComponentLookupError

Àlex Magaz Graça
Hello,

I have an application with code like this:

from zope.component import getUtility
from zope.catalog.interfaces import ICatalog
...

class TicketCatalog(grok.Container):
     ...
     def getActiveTickets(self):
         catalog = getUtility(ICatalog)
         ...

after following the code at the end of the example here:

http://grok.zope.org/doc/current/reference/components.html#grok.index.Value

But when called from a unit test, I get this:

Error in test testGetActiveTickets
(helpdesk.tests.test_helpdesk.TicketCatalogTest)
Traceback (most recent call last):
   File "/usr/lib/python2.7/unittest/case.py", line 321, in run
     testMethod()
   File
"/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/tests/test_helpdesk.py",
line 29, in testGetActiveTickets
     activeTickets = self._catalog.getActiveTickets()
   File
"/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/app.py",
line 31, in getActiveTickets
     catalog = getUtility(ICatalog)
   File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py",
line 169, in getUtility
     raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass
zope.catalog.interfaces.ICatalog>, '')

Also, if I try from a python console:

$ bin/python-console
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import zope.component
 >>> from zope.catalog.interfaces import ICatalog
 >>> catalog = zope.component.getUtility(ICatalog)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py",
line 169, in getUtility
     raise ComponentLookupError(interface, name)
zope.component.interfaces.ComponentLookupError: (<InterfaceClass
zope.catalog.interfaces.ICatalog>, '')

Any idea of what I'm doing wrong?

If it helps, I'm running it from an Ubuntu 11.04 with the following
versions reported from the Grok admin interface:

Grok: 1.6 (is this right? the last announced version from the web is 1.4)
Python: 2.7.1
Zope version: Unavailable (?)

And from python path:

/home/alex/.buildout/eggs/zope.catalog-3.8.1-py2.7.egg
/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg

Thanks,
Àlex
_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Sylvain Viollon

Op 9 nov 2011, om 23:16 heeft Àlex Magaz Graça het volgende geschreven:

> Hello,
>

   Hello,

> I have an application with code like this:
>
> from zope.component import getUtility
> from zope.catalog.interfaces import ICatalog
> ...
>
> class TicketCatalog(grok.Container):
>     ...
>     def getActiveTickets(self):
>         catalog = getUtility(ICatalog)
>         ...
>
> after following the code at the end of the example here:
>
> http://grok.zope.org/doc/current/reference/components.html#grok.index.Value
>


    I you call a method of your content that rely on your Grok site directly from a unittest, you need to setup your Grok as a local site for the Zope component architecture. This is automatically done by publisher when your Grok site is traversed in a request.

    In your unittest you need to do before:

    from zope.component.hooks import setSite, getSite

    setSite(self.yourgroksite)

    If you after call getSite(), your Grok must be returned. The setup of your testcase is a good place to do that I think.

    Regards,

    Sylvain


--
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands



_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Àlex Magaz Graça
El 10/11/11 09:24, Sylvain Viollon escribió:
Op 9 nov 2011, om 23:16 heeft Àlex Magaz Graça het volgende geschreven:

Hello,

   Hello,

I have an application with code like this:

from zope.component import getUtility
from zope.catalog.interfaces import ICatalog
...

class TicketCatalog(grok.Container):
    ...
    def getActiveTickets(self):
        catalog = getUtility(ICatalog)
        ...

after following the code at the end of the example here:

http://grok.zope.org/doc/current/reference/components.html#grok.index.Value


    I you call a method of your content that rely on your Grok site directly from a unittest, you need to setup your Grok as a local site for the Zope component architecture. This is automatically done by publisher when your Grok site is traversed in a request.

    In your unittest you need to do before:

    from zope.component.hooks import setSite, getSite

    setSite(self.yourgroksite)

    If you after call getSite(), your Grok must be returned. The setup of your testcase is a good place to do that I think.

    Regards,

    Sylvain



Thanks for your quick response!

I've been trying but still no luck :/

First I've added a setUp() method with a call to setSite() like this (where Helpdesk is a grok.Application):

class TicketCatalogTest(unittest.TestCase):
    def setUp(self):
        helpdesk = Helpdesk()
        self._catalog = helpdesk.ticketCatalog
        setSite(helpdesk)

but I get this:

Error in test testGetActiveTickets (helpdesk.tests.test_helpdesk.TicketCatalogTest)
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 312, in run
    self.setUp()
  File "/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/tests/test_helpdesk.py", line 23, in setUp
    setSite(helpdesk)
  File "/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/hooks.py", line 67, in setSite
    sm = site.getSiteManager()
  File "/home/alex/.buildout/eggs/zope.site-3.9.2-py2.7.egg/zope/site/site.py", line 76, in getSiteManager
    raise ComponentLookupError('no site manager defined')
ComponentLookupError: no site manager defined

Then, greping around in ~/.buildout I found some tests which set a site manager, so I end up with the following code:

    def setUp(self):
        helpdesk = Helpdesk()
        self._catalog = helpdesk.ticketCatalog

        setHooks()
        provideAdapter(
            SiteManagerAdapter, (Interface,), IComponentLookup)
        site = rootFolder()
        site.setSiteManager(LocalSiteManager(site))
        setSite(site)

But then again the look up error:

Error in test testGetActiveTickets (helpdesk.tests.test_helpdesk.TicketCatalogTest)
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 321, in run
    testMethod()
  File "/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/tests/test_helpdesk.py", line 45, in testGetActiveTickets
    activeTickets = self._catalog.getActiveTickets()
  File "/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/app.py", line 31, in getActiveTickets
    catalog = getUtility(ICatalog)
  File "/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py", line 169, in getUtility
    raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass zope.catalog.interfaces.ICatalog>, '')

I've tried several variations of this codes, but there's always something that fails. So I'm back to the beginning.

Any idea of what is missing? A link to documentation about this or code examples would be very useful. I didn't find anything.

Thanks,
Àlex

_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Christian Klinger
Hi,

what kind of testsetup do you use in your unittest?
Do you use the default setup?

Christian

> El 10/11/11 09:24, Sylvain Viollon escribió:
>> Op 9 nov 2011, om 23:16 heeftÀlex Magaz Graça het volgende geschreven:
>>
>>> Hello,
>>>
>>     Hello,
>>
>>> I have an application with code like this:
>>>
>>> from zope.component import getUtility
>>> from zope.catalog.interfaces import ICatalog
>>> ...
>>>
>>> class TicketCatalog(grok.Container):
>>>      ...
>>>      def getActiveTickets(self):
>>>          catalog = getUtility(ICatalog)
>>>          ...
>>>
>>> after following the code at the end of the example here:
>>>
>>> http://grok.zope.org/doc/current/reference/components.html#grok.index.Value
>>>
>>
>>      I you call a method of your content that rely on your Grok site directly from a unittest, you need to setup your Grok as a local site for the Zope component architecture. This is automatically done by publisher when your Grok site is traversed in a request.
>>
>>      In your unittest you need to do before:
>>
>>      from zope.component.hooks import setSite, getSite
>>
>>      setSite(self.yourgroksite)
>>
>>      If you after call getSite(), your Grok must be returned. The setup of your testcase is a good place to do that I think.
>>
>>      Regards,
>>
>>      Sylvain
>>
>>
>
> Thanks for your quick response!
>
> I've been trying but still no luck :/
>
> First I've added a setUp() method with a call to setSite() like this
> (where Helpdesk is a grok.Application):
>
> class TicketCatalogTest(unittest.TestCase):
> def setUp(self):
> helpdesk = Helpdesk()
> self._catalog = helpdesk.ticketCatalog
> setSite(helpdesk)
>
> but I get this:
>
> Error in test testGetActiveTickets
> (helpdesk.tests.test_helpdesk.TicketCatalogTest)
> Traceback (most recent call last):
> File "/usr/lib/python2.7/unittest/case.py", line 312, in run
> self.setUp()
> File
> "/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/tests/test_helpdesk.py",
> line 23, in setUp
> setSite(helpdesk)
> File
> "/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/hooks.py",
> line 67, in setSite
> sm = site.getSiteManager()
> File
> "/home/alex/.buildout/eggs/zope.site-3.9.2-py2.7.egg/zope/site/site.py",
> line 76, in getSiteManager
> raise ComponentLookupError('no site manager defined')
> ComponentLookupError: no site manager defined
>
> Then, greping around in ~/.buildout I found some tests which set a site
> manager, so I end up with the following code:
>
> def setUp(self):
> helpdesk = Helpdesk()
> self._catalog = helpdesk.ticketCatalog
>
> setHooks()
> provideAdapter(
> SiteManagerAdapter, (Interface,), IComponentLookup)
> site = rootFolder()
> site.setSiteManager(LocalSiteManager(site))
> setSite(site)
>
> But then again the look up error:
>
> Error in test testGetActiveTickets
> (helpdesk.tests.test_helpdesk.TicketCatalogTest)
> Traceback (most recent call last):
> File "/usr/lib/python2.7/unittest/case.py", line 321, in run
> testMethod()
> File
> "/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/tests/test_helpdesk.py",
> line 45, in testGetActiveTickets
> activeTickets = self._catalog.getActiveTickets()
> File
> "/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/app.py",
> line 31, in getActiveTickets
> catalog = getUtility(ICatalog)
> File
> "/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py",
> line 169, in getUtility
> raise ComponentLookupError(interface, name)
> ComponentLookupError: (<InterfaceClass
> zope.catalog.interfaces.ICatalog>, '')
>
> I've tried several variations of this codes, but there's always
> something that fails. So I'm back to the beginning.
>
> Any idea of what is missing? A link to documentation about this or code
> examples would be very useful. I didn't find anything.
>
> Thanks,
> Àlex
>
>
> _______________________________________________
> Grok-dev mailing list
> [hidden email]
> https://mail.zope.org/mailman/listinfo/grok-dev


_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Uli Fouquet
Hi there,

Am Freitag, den 11.11.2011, 09:14 +0100 schrieb Christian Klinger:

> what kind of testsetup do you use in your unittest?
> Do you use the default setup?

From the snippets sent by Alex I get the impression that the test setup
is rather plain: no layer, no 'FunctionalTestCase' of any kind, just
pure unittest.TestCase.

In case of catalogs that quickly means trouble. While Sylvains hint to
use setSite() is correct, there are still some caveats to consider:

Catalogs are created automatically when you add a grok.Application
instance (like a HelpDesk instance) to the ZODB. The catalog creation is
triggered by an event handler for IObjectAddedEvent.

So, there should be no need to create the catalog in tests manually.

To have a ZODB available during testing, you certainly want some kind of
'functional' test setup. What you need then, is some real 'root' meaning
the root object of the ZODB activated during tests. This is normally the
main thing created by functional test setups (beside registrations and
all that).

If you have this root, you should be able to follow the examples from
docs as stated:

  >>> root['app'] = HelpDesk()
  >>> from zope.component.hooks import setSite
  >>> setSite(root['app'])

and also the catalog lookup should work.

By the way: if you use `bin/interactive_debugger` instead of
`bin/python_console` you should get a functional environment around your
Python shell where you can do things like above as you like. One main
difference is: you get a 'root' of ZODB and all components defined in
your code (like the indexes etc.) are registered on startup of this
'high-level' console. The interactive debugger has access to the local
ZODB (but be aware that you work on the real ZODB data there).

A nice side-effect if you do 'functional' testing is that new objects
added to the ZODB (yes, they won't be catalogued before put in the ZODB,
because catalogs also rely on IObjectAddedEvents which are triggered by
ZODB additions) will be searchable afterwards.

Otherwise - after enourmous efforts to make your catalog findable in a
pure unittest.TestCase environment - you might hit the next big problem:
your objects won't be catalogued as expected.

I admit that setting up catalogs and their persistence is really
difficult or even nasty to manage sometimes (just think of the problems
when trying to add/remove indexes from existing catalogs), but for now I
don't know of something better.

Best regards,

--
Uli

_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Àlex Magaz Graça
El 11/11/11 13:28, Uli Fouquet escribió:

> Hi there,
>
> Am Freitag, den 11.11.2011, 09:14 +0100 schrieb Christian Klinger:
>
>> what kind of testsetup do you use in your unittest?
>> Do you use the default setup?
>  From the snippets sent by Alex I get the impression that the test setup
> is rather plain: no layer, no 'FunctionalTestCase' of any kind, just
> pure unittest.TestCase.
>
> In case of catalogs that quickly means trouble. While Sylvains hint to
> use setSite() is correct, there are still some caveats to consider:
>
> Catalogs are created automatically when you add a grok.Application
> instance (like a HelpDesk instance) to the ZODB. The catalog creation is
> triggered by an event handler for IObjectAddedEvent.
>
> So, there should be no need to create the catalog in tests manually.
>
> To have a ZODB available during testing, you certainly want some kind of
> 'functional' test setup. What you need then, is some real 'root' meaning
> the root object of the ZODB activated during tests. This is normally the
> main thing created by functional test setups (beside registrations and
> all that).
>
> If you have this root, you should be able to follow the examples from
> docs as stated:
>
>    >>>  root['app'] = HelpDesk()
>    >>>  from zope.component.hooks import setSite
>    >>>  setSite(root['app'])
>
> and also the catalog lookup should work.
>
> By the way: if you use `bin/interactive_debugger` instead of
> `bin/python_console` you should get a functional environment around your
> Python shell where you can do things like above as you like. One main
> difference is: you get a 'root' of ZODB and all components defined in
> your code (like the indexes etc.) are registered on startup of this
> 'high-level' console. The interactive debugger has access to the local
> ZODB (but be aware that you work on the real ZODB data there).
>
> A nice side-effect if you do 'functional' testing is that new objects
> added to the ZODB (yes, they won't be catalogued before put in the ZODB,
> because catalogs also rely on IObjectAddedEvents which are triggered by
> ZODB additions) will be searchable afterwards.
>
> Otherwise - after enourmous efforts to make your catalog findable in a
> pure unittest.TestCase environment - you might hit the next big problem:
> your objects won't be catalogued as expected.
>
> I admit that setting up catalogs and their persistence is really
> difficult or even nasty to manage sometimes (just think of the problems
> when trying to add/remove indexes from existing catalogs), but for now I
> don't know of something better.
>
> Best regards,

Hi Christian and Uli,

You were right, the problem was I had a plain unit test. Now it founds
ICatalog, but another error appears:

File
"/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/tests/app.txt",
line 15, in app.txt
Failed example:
     t1 = catalog.openNewTicket("0", "summary1", "description1")
Exception raised:
     Traceback (most recent call last):
       File "/usr/lib/python2.7/doctest.py", line 1254, in __run
         compileflags, 1) in test.globs
       File "<doctest app.txt[6]>", line 1, in <module>
         t1 = catalog.openNewTicket("0", "summary1", "description1")
       File
"/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/app.py",
line 22, in openNewTicket
         self[ str(ticketNumber) ] = Ticket(ticketNumber, uid, summary,
description)
       File
"/home/alex/.buildout/eggs/zope.container-3.12.0-py2.7-linux-x86_64.egg/zope/container/btree.py",
line 112, in __setitem__
         setitem(self, self._setitemf, key, value)
       File
"/home/alex/.buildout/eggs/zope.container-3.12.0-py2.7-linux-x86_64.egg/zope/container/contained.py",
line 559, in setitem
         notify(event)
       File
"/home/alex/.buildout/eggs/zope.event-3.5.0_1-py2.7.egg/zope/event/__init__.py",
line 23, in notify
         subscriber(event)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/event.py",
line 24, in dispatch
         zope.component.subscribers(event, None)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py",
line 136, in subscribers
         return sitemanager.subscribers(objects, interface)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/registry.py",
line 321, in subscribers
         return self.adapters.subscribers(objects, provided)
       File
"/home/alex/.buildout/eggs/zope.interface-3.6.3-py2.7-linux-x86_64.egg/zope/interface/adapter.py",
line 583, in subscribers
         subscription(*objects)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/event.py",
line 32, in objectEventNotify
         zope.component.subscribers((event.object, event), None)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py",
line 136, in subscribers
         return sitemanager.subscribers(objects, interface)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/registry.py",
line 321, in subscribers
         return self.adapters.subscribers(objects, provided)
       File
"/home/alex/.buildout/eggs/zope.interface-3.6.3-py2.7-linux-x86_64.egg/zope/interface/adapter.py",
line 583, in subscribers
         subscription(*objects)
       File
"/home/alex/.buildout/eggs/zope.intid-3.7.2-py2.7.egg/zope/intid/__init__.py",
line 166, in addIntIdSubscriber
         key = IKeyReference(ob, None)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/hookable.py",
line 33, in __call__
         return self.__implementation(*args, **kw)
       File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/hooks.py",
line 104, in adapter_hook
         return siteinfo.adapter_hook(interface, object, name, default)
       File
"/home/alex/.buildout/eggs/zope.security-3.8.2-py2.7-linux-x86_64.egg/zope/security/adapter.py",
line 86, in __call__
         adapter = self.factory(*args)
       File
"/home/alex/.buildout/eggs/zope.keyreference-3.6.2-py2.7.egg/zope/keyreference/persistent.py",
line 40, in __init__
         raise zope.keyreference.interfaces.NotYet(object)
     NotYet: <helpdesk.app.Ticket object at 0x3d62938>

I found the following thread, but I think it doesn't apply in my case as
I'm not adding anything from __init__()

http://osdir.com/ml/web.zope.grok.devel/2007-07/msg00143.html

My code is something like this:

class Helpdesk(grok.Application, grok.Container):
     def __init__(self):
         super(Helpdesk, self).__init__()
         self.ticketCatalog = TicketCatalog()

class TicketCatalog(grok.Container):
     def __init__(self):
         super(TicketCatalog, self).__init__()

     def openNewTicket(self, uid, summary, description):
         ticketNumber = self.nextTicketNumber()
         self[ str(ticketNumber) ] = Ticket(ticketNumber, uid, summary,
description)

class Ticket(grok.Model):
     ...

and my functional test:

 >>> from helpdesk.app import Helpdesk
 >>> from zope.component.hooks import setSite
 >>> root = getRootFolder()
 >>> root['app'] = Helpdesk()
 >>> setSite(root['app'])
 >>> catalog = root['app'].ticketCatalog
 >>> t1 = catalog.openNewTicket("0", "summary1", "description1")
 >>> activeTickets = catalog.getActiveTickets()
 >>> len(activeTickets)
     1


Am I doing something wrong?

Thanks,
Àlex
_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Àlex Magaz Graça
Hi! I finally got it right. The problem was in the following snipped:

> [...]
> class Helpdesk(grok.Application, grok.Container):
>     def __init__(self):
>         super(Helpdesk, self).__init__()
>         self.ticketCatalog = TicketCatalog()
>

Adding the TicketCatalog object to the Helpdesk container like below
solved the problem:

def __init__(self):
         super(Helpdesk, self).__init__()
         self.ticketCatalog = TicketCatalog()
         self["ticketCatalog"] = self.ticketCatalog

It also solved a problem with the ticket indexes not being updated
automatically. This fix looks a bit weird to me, though.
I guess I should structure the code in way that fits better with Grok...

Cheers,
Àlex

_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Sylvain Viollon

Hello,

Op 14 nov 2011, om 22:57 heeft Àlex Magaz Graça het volgende geschreven:

> Hi! I finally got it right. The problem was in the following snipped:
>
>> [...]
>> class Helpdesk(grok.Application, grok.Container):
>>    def __init__(self):
>>        super(Helpdesk, self).__init__()
>>        self.ticketCatalog = TicketCatalog()
>>
>
> Adding the TicketCatalog object to the Helpdesk container like below
> solved the problem:
>
> def __init__(self):
>         super(Helpdesk, self).__init__()
>         self.ticketCatalog = TicketCatalog()

   This set the catalog as an attribute of your folder class. No events happens.
Nothing happens, except the catalog is pickled in the database.

>         self["ticketCatalog"] = self.ticketCatalog
>

   This set the catalog as an element in your folder item. Added events are triggered,
that probably initialize the catalog itself.

   Regards,

   Sylvain,

--
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands



_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getUtility(ICatalog) fails with ComponentLookupError

Uli Fouquet
Hi there,

Somehow Alex postings to the list seem to get lost on their way to my
mailbox. Is there something I can do (no, the mails didn't go to the
spam folder)? I only noticed he posted by seeing the replies and looking
into the web-archive.

Am Dienstag, den 15.11.2011, 10:59 +0100 schrieb Sylvain Viollon:

> Hello,
>
> Op 14 nov 2011, om 22:57 heeft Àlex Magaz Graça het volgende geschreven:
>
> > Hi! I finally got it right. The problem was in the following snipped:
> >
> >> [...]
> >> class Helpdesk(grok.Application, grok.Container):
> >>    def __init__(self):
> >>        super(Helpdesk, self).__init__()
> >>        self.ticketCatalog = TicketCatalog()
> >>
> >
> > Adding the TicketCatalog object to the Helpdesk container like below
> > solved the problem:
> >
> > def __init__(self):
> >         super(Helpdesk, self).__init__()
> >         self.ticketCatalog = TicketCatalog()
>
>    This set the catalog as an attribute of your folder class. No events happens.
> Nothing happens, except the catalog is pickled in the database.
>
> >         self["ticketCatalog"] = self.ticketCatalog
> >
>
>    This set the catalog as an element in your folder item. Added events are triggered,
> that probably initialize the catalog itself.
Yep, that might be true and this difference is important to remember:
adding items to a container triggers IObjectAddedEvent while setting
attributes of a container does not (at least not automatically).

I nevertheless do not understand, why the catalog is not created
automatically.

Normally, your catalog should be created automatically when you create a
HelpDesk instance and store it into ZODB (as a container item). But that
requires the ComponentArchitecture to be in place and a ZODB to store
the instance in.

Best regards,

--
Uli


_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev

signature.asc (196 bytes) Download Attachment
Loading...