On Fri, Oct 03, 2008 at 11:37:35AM +0100, Adam wrote:
> Hi, I wonder if anyone can help me.
> I've got a custom Python cgi which runs in one directory using ZODB for
> the database. It runs in a directory off the site root ie. /System
> It's got a bit unwieldy in there so I wanted to separate the core
> modules out as I don't really touch them any more, so adding
> subdirectories:
> /System/Core
> /System/Application
> In System, I created a dummy frontend CGI like the following:
> # /System/frontend.py
> import ZODB
> from Core import *
> from Application import *
> site = Start.ProcessRequest()  # Start is a module in Core
> site.Main()
> For some reason, all the Persistent derived objects in the database are
> returning:  <broken Module.Class instance>
> Does ZODB do something with __import__ modules which may cause it to
> lose the references to the classes/modules?

The ZODB stores fully qualified class names (package.module.class).  If
you move the modules around, ZODB can no longer find the classes in
their old locations.

> Is there any way to fix the database

Yes, but it's not pretty:

  1. create modules in their old locations that import all the classes
     from the new locations (and do nothing else).
  2. write a script that opens the DB, iterates over all persistent
     objects in it, touches every single one of them (obj._p_activate()
     followed by obj._p_changed = True) and commits the transaction.

If you've done everything right, now the database should refer to all
the classes using their new locations.

> or do I have to return to putting
> all my .py files in one directory.

Third alternative: create modules for backwards compatibility (just the
step 1 described above).

Marius Gedminas
Those who can't write, write manuals.

Attachment: signature.asc
Description: Digital signature

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to