[Grok-dev] Persistence issue with grok.Model

Robert Marianski rmarianski at openplans.org
Mon Dec 29 15:16:48 EST 2008


On Mon, 2008-12-29 at 20:43 +0100, Andreas Jung wrote:
> Hi there,
> 
> I am current encountering a persistence issue with the following:
> A Grok app "Server" contains a container "Accounting" holding instances 
> of "Job":
> 
> class Server(grok.Application, grok.Container):
>      """ This is the base of all evil """
> 
>      interface.implements(IServer)
> 
>      title = u''
>      spool_directory = default_tempdir
> 
>      def addJob(self, *args, **kw):
>          if not 'accounting' in self:
>              self['accounting'] = Accounting()
>          self['accounting'].addJob(*args, **kw)
>          self._p_changed = 1
> 
> class Accounting(grok.Container):
>      """ A folder for Job objects """
> 
>      num_items = 0
> 
>      def addJob(self, *args, **kw):
>          self.num_items += 1
>          self[str(self.num_items)] = Job(*args, **kw)
>          self._p_changed = 1
> 
> 
> class Job(grok.Model):
>      """ Holds informations about each conversion job """
> 
>      def __init__(self, *args, **kw):
>          super(Job, self).__init__()
>          for k,v in kw.items():
>              setattr(self, k, v)
> 
> 
> So Server.addJob(**kw) create a new Job instance within the Accouting
> container where the **kw parameters are added as instances attributes
> (I need this very generic approach).
> 
> The mess starts after having created a view for displaying the jobs:
> 
> class ShowJobs(grok.View):
>      grok.context(Zopyx_smartprintng_server)
> 
>      def getJobs(self):
>          lst = list()
>          for id, job in self.context['accounting'].items():
>              print id, job.__dict__
>              lst.append(job.__dict__.copy())
>          return lst
> 
> The instance dict of a Job instance holds the **kw dict until I restart
> my Grok instance. After the restart the instance dict is empty. Is there 
> something I am missing or some further magic involved (do I need a 
> schema for a Grok Model in order for having the instance dict properly
> persisted)?
> 
> Andreas

Are you using python2.5? I've heard of persistence problems at some
point with python 2.5 like you describe. I think it had something to do
with python2.5 and 64 bit linux machines. I don't remember the details
now though.

Robert




More information about the Grok-dev mailing list