[Grok-dev] Re: ModelTraverse on the application

Philipp von Weitershausen philipp at weitershausen.de
Thu Aug 16 05:53:50 EDT 2007


Wichert Akkerman wrote:
> I'm working on an application which does not use the ZODB but keeps all
> data in SQL. It seems that the best way to model that in grok is to use
> model classes that map the SQL data and use the standard ModelTraverse
> to go over them.
> 
> Unfortunately this does not seem to work for the application. I use
> this simple test:
> 
>     import grok
>     from saturn.status import Status
>     # Status is a simple grok.Model derived class
>     
>     class saturn(grok.Application):
>         def __init__(self):
>             super(saturn, self).__init__(self)
>             self.status = Status()

For the list record, you also need to inherit from either grok.Model, 
grok.Container or some other persistent base class.

>     class Index(grok.View):
>         grok.context(saturn)
> 
> For some reason I have to explicitly tell grok what the context for
> Index is. That is no big deal though, but this is: as soon as I visit
> /status in my application I get this traceback:
> 
> 2007-08-16T11:04:56 ERROR ZODB.Connection Couldn't load state for 0x03
> Traceback (most recent call last):
>   ...
> TypeError: Cache values must be persistent objects.
> 
> that is somewhat unexpected to me. Is my pattern wrong here?

Nope. I think it's a good idea to make your SQL objects available 
through a custom traverser.


-- 
http://worldcookery.com -- Professional Zope documentation and training


More information about the Grok-dev mailing list