librelist archives

« back to archive

Hello everyone

Hello everyone

From:
Matias Pansa
Date:
2012-08-02 @ 20:52
Hi , i'm Matias from Argentina , i'm using flask to develop a web app
, it's almost done but testing a zodb connection i find a problem ,
when i retrieve the resultset from zodb with values() method the
objects in the list are broken  , when i test it outside flask to
check the objects on zodb oobtree it's ok and the list have all the
objects and methods of the class  , i check all imports and classes  .

In flask says "Posicion object has no attribute hora" , the class is
correct but i cant't use any method.

Thanks, Matias

Re: [flask] Hello everyone

From:
Simon Sapin
Date:
2012-08-02 @ 22:05
Le 02/08/2012 22:52, Matias Pansa a écrit :
> Hi , i'm Matias from Argentina , i'm using flask to develop a web app
> , it's almost done but testing a zodb connection i find a problem ,
> when i retrieve the resultset from zodb with values() method the
> objects in the list are broken  , when i test it outside flask to
> check the objects on zodb oobtree it's ok and the list have all the
> objects and methods of the class  , i check all imports and classes  .
>
> In flask says "Posicion object has no attribute hora" , the class is
> correct but i cant't use any method.
>
> Thanks, Matias

Hi Matias,

Can you show some code? In particular, the definition for the class of 
the ZODB object and the part where you save and load it. We can’t really 
help with this little information. The best would be to give enough so 
that we can reproduce the problem.

This is only a wild guess, but is your Posicion class at the top-level 
of an importable module? Ie. not inside a function or another class. 
Non-top-level classes are common problem with pickle, which I think ZODB 
uses for serializing objects.

Cheers,
-- 
Simon Sapin

Re: [flask] Hello everyone

From:
Matias Pansa
Date:
2012-08-02 @ 22:41
Hi Simon , this is the Posicion class , i try to put it in many places
 with no results , always at top level.

class Posicion():

            def __init__(self):

                self.id=''
                self.hora=''
                self.lat=''
                self.lon=''
                self.antpos=''
                self.velocidad=''
                self.distancia=''



I'm running zeo wich my app uses to connect to the database , i'm
using a module called condb to simplify the connection at app level


condb.py

from ZODB.FileStorage import FileStorage
from ZODB.DB import DB
import transaction
from BTrees.OOBTree import OOBTree
import threading
from ZEO import ClientStorage



class Condb(object):  # Inicializa la conexion a la base de datos



          def __init__(self, base):

              addr  = '190.183.223.30', 8010
             # Direccion de la base de datos
              posiciones  = '190.183.223.30', 8011
                   # Direccion de la base de datos
              usuarios  = '190.183.223.30', 8012
                 # Direccion de la base de datos

              if (base[0] == 'usuarios') :

                  self.storage = ClientStorage.ClientStorage(usuarios)
       # Tipo de almacenamiento

              elif ( base[0] == 'posiciones') :

                  self.storage =
ClientStorage.ClientStorage(posiciones)        # Tipo de
almacenamiento

              else :

                  self.storage = ClientStorage.ClientStorage(addr)
   # Tipo de almacenamiento
			
			
              #transaction.begin()
              self.db = DB(self.storage)
             # Se conecta al almacenamiento
              self.connection = self.db.open()
       # Se abre el almacenamiento
              self.dbroot = self.connection.root()
       # Se obtiene la raiz del almacenamiento

              if base[0]=='posiciones' :

                  self.nombrebase=base[1]
       # Se obtiene la table especifica de la base de datos segun
elparametro de entrada
              else :
			
                  self.nombrebase=base[0]
	
              #self.dbroot[self.nombrebase]=OOBTree()
              #transaction.commit()
              self.s= self.dbroot[self.nombrebase]
     # Se almacena la tabla independientemente

          def datos(self) : # Devuelve los datos dela tabla almacenada
como una lista de valores

              return self.dbroot[self.nombrebase].values()


          def cerrar(self): # Cierra la conexion a la base de datos

              self.connection.close()
              self.db.close()
              self.storage.close()

          def raiz(self) :
		
		      return self.s


The method "datos" on "condb" module returns the resultset from zodb
database , outside flask app i use a python script called "vista.py"
just to check
the database , vista.py connects to zeo the same way my flask app does
it via "condb.py" module, and works perfect with the correct
resultset,
the resultset is a list o Posicion objects.

Using the same method to connect to zeo from flask app returns a
broken list of Posicion objects , using dir() method to check the
objects is a list of
broken Posicion objects , this is one Poscision :

['__Broken_initargs__', '__Broken_newargs__', '__Broken_state__',
'__class__', '__delattr__', '__dict__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__implemented__', '__init__',
'__module__', '__name__', '__new__', '__providedBy__', '__provides__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__setstate__', '__sizeof__', '__str__', '__subclasshook__',
'__weakref__']


wich must be :

['__doc__', '__init__', '__module__', 'antpos', 'distancia', 'hora',
'id', 'lat', 'lon', 'velocidad']




Matias.


2012/8/2 Simon Sapin <simon.sapin@exyr.org>:
> Le 02/08/2012 22:52, Matias Pansa a écrit :
>> Hi , i'm Matias from Argentina , i'm using flask to develop a web app
>> , it's almost done but testing a zodb connection i find a problem ,
>> when i retrieve the resultset from zodb with values() method the
>> objects in the list are broken  , when i test it outside flask to
>> check the objects on zodb oobtree it's ok and the list have all the
>> objects and methods of the class  , i check all imports and classes  .
>>
>> In flask says "Posicion object has no attribute hora" , the class is
>> correct but i cant't use any method.
>>
>> Thanks, Matias
>
> Hi Matias,
>
> Can you show some code? In particular, the definition for the class of
> the ZODB object and the part where you save and load it. We can’t really
> help with this little information. The best would be to give enough so
> that we can reproduce the problem.
>
> This is only a wild guess, but is your Posicion class at the top-level
> of an importable module? Ie. not inside a function or another class.
> Non-top-level classes are common problem with pickle, which I think ZODB
> uses for serializing objects.
>
> Cheers,
> --
> Simon Sapin