[Zope] ZODB Persistence problem

Emiliano Marmonti emarmonti at siu.edu.ar
Thu Sep 18 20:48:42 EDT 2003


Hello all

I'm trying to do an application that handles it own ZODB database for
storing large hierarcichal data. The abstractions and the db access are
in external method and I use DTML for querying and receiving data to
store. I have seen some examples like that about using ZODB from outside
of Zope. I have integrated the database with a catalog to search inside
it.

Now I have a problem that have no idea how to fix it. Could
add objects into a ZODB separate database, could add the catalog and the

index, but when the database has one element, with every operation
(inclusive opening it) this message appears from Zope:

'App.PersistentExtra' module has no attribute 'Autor'

>From Python

  File C:\Archivos de programa\Zope\lib\python\ZODB\Connection.py, line
534, in etstate
  File C:\Archivos de programa\Zope\lib\python\ZODB\Connection.py, line
178, in_persistent_load
    (Info: ('\x00\x00\x00\x00\x00\x00\x00\x0e', ('App.PersistentExtra',
'Autor')))
  File C:\Archivos de programa\Zope\lib\python\ZODB\Connection.py, line
138, in __getitem__
    (Info: ('\x00\x00\x00\x00\x00\x00\x00\x0e',
'((U\x13App.PersistentExtraq\x01U\x05Autorq\x02tq\x03Nt.}q\x04(U\x02idq\x05U\x0822596451q\x06U\x04nameq\x07U\x0f

Juana Silviaq\x08U\robservacionesq\tU\x0bpruebaq\nu.'))
  File C:\Archivos de programa\Zope\lib\python\ZODB\DB.py, line 122, in
_classFa
ctory
AttributeError: 'App.PersistentExtra' module has no attribute 'Autor'

Simply, I have no idea what is happening, have searched over
App.PersistentExtra but...what is???? Somebody knows where could I find
an example (that works and is updated) for doing this kind of tasks?

My code is:
-----------------------------
import sys
import ZODB
import Persistence
from Persistence import Persistent
from ZODB.FileStorage import FileStorage
from Products.ZCatalog.Catalog import Catalog
from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex

class Autor(Persistent):
     id=''
     name=''
     observaciones=''

     def __init__(self,id,nombre,comments):
         self.name = nombre
         self.id = id
         self.observaciones = comments

     def setName(self,nombre):
         self.name = nombre

     def setId(self,id):
         self.id = id

     def setObs(self,comments):
         self.observaciones = comments

     def getName(self):
         return self.name

     def getId(self):
         return self.id


class Autores:
     def __init__( self, file='dcAuthor.fs' ):
        self.file= file
        self.db  = ZODB.DB( FileStorage( file ) )
        self.co  = self.db.open()
        self.root= self.co.root()
        if self.root.has_key( 'cat' ):
             self.cat= self.root['cat']
        else:
             self.cat        = Catalog()
      ### This is, how I get it to work
             self.cat.aq_parent= self.root
             self.root['cat']= self.cat

             ### Add indexes to the Catalog-Class
             ### The names must match the fields of the Person-Class!

              indice = FieldIndex('id')
             self.cat.addIndex('id',indice )
             otroIndice = FieldIndex('name')
             self.cat.addIndex('name' ,otroIndice )
###            self.cat.addIndex('observaciones','FieldIndex' )
             get_transaction().commit()

     def setAutor( self, autor ):
         uid= id( autor )
         self.root[uid]= autor
         print "Guardada como:"+str(uid)

        ### Let the Catalog know from this object
        self.cat.catalogObject( autor, uid )
        get_transaction().commit()

     def searchAutor( self, **kw ):
        r= self.cat.searchResults( kw )
        paths= self.cat.paths
        root = self.root
        k= []
        for i in r:
                 id= i.data_record_id_
                 k.append( root[paths[id]] )
        return k

     def close ( self ):
        self.db.close()



def AddAutor(nombre,documento,obs):
   autor = Autor(documento,nombre,obs)
   autores = Autores()
   autores.setAutor(autor)
   autores.close()

def GetAutor(expresion):
   autores = Autores()
   listaAutores=autores.searchAutor(name=expresion)
   autores.close()
   listaretorno=[]
   for au in listaAutores:
      listaretorno.append(au.getName())
   return listaretorno

----------------------------------------

I've seen that if I no close() the database, only obtain Error 500 from
the server. GetAutor and AddAutor are called from DTML.

Well, thanks a lot.
Emiliano.




More information about the Zope mailing list