[ZODB-Dev] Persistent classes

Paolo Invernizzi paoloinvernizzi at dmsware.com
Mon May 5 18:39:54 EDT 2003


Hi all,

I've this problem...

WinXP SP1
Python CVS (compiled with VC.NET 2003 Final)
ZODB4 CVS  (compiled with VC.NET 2003 Final)

./remote/app.py
===============
from persistence import Persistent
class App(Persistent):
     pass

./genesi.py
===========
import zodb.db
from zodb.storage.file import FileStorage
from zodb.code.module import ManagedRegistry
from transaction import get_transaction


db=zodb.db.DB(FileStorage("./db.fs",create=True))
root=db.open().root()
registry=ManagedRegistry()
registry.newModule("app",file("./remote/app.py").read())

root["registry"]=registry
get_transaction().commit()

./genesi2.py
============
import zodb.db
from zodb.storage.file import FileStorage
from zodb.code.module import ManagedRegistry, PersistentModuleImporter
from transaction import get_transaction

#--- Very pedantic from test_module.py
class TestPersistentModuleImporter(PersistentModuleImporter):
     def __init__(self,registry):
         self._registry=registry
         self._registry._p_activate()

     def __import__(self,name,globals={},locals={},fromlist=[]):
 
mod=self._import(self._registry,name,self._get_parent(globals),fromlist)
         if mod is not None:
             return mod
         return self._saved_import(name,globals,locals,fromlist)

db=zodb.db.DB(FileStorage("./db.fs"))
root=db.open().root()
registry=root["registry"]

importer=TestPersistentModuleImporter(registry)
importer.install()

import app
print "module app   :",app
print "class app.App:",app.App

theApp=app.App()
print "instance theApp:",theApp

root["theapp"]=theApp
get_transaction().commit()


D:\temp>python_d genesi.py
[14464 refs]

D:\temp>python_d genesi2.py
module app   : <PersistentModule app>
class app.App: <type 'persistence.Persistent'>
instance theApp: <persistence.Persistent object at 0x00B1C678>

Unhandled Exception. Persistence.c line 140
Basically the
PyObject **pdict = _PyObject_GetDictPtr(self);
at 128 returns a NULL...

I'm sure I've done something very silly....

How to persist an instance of a persistent-class?

Thanks in advance.

---
Paolo Invernizzi





More information about the ZODB-Dev mailing list