[Zope3-dev] Re: Replacing class refs in ZODB
Jim Fulton
jim at zope.com
Fri Feb 18 12:38:48 EST 2005
Derrick Hudson wrote:
> On Fri, Feb 18, 2005 at 11:59:04AM -0500, Jim Fulton wrote:
> | Garrett Smith wrote:
> | >Jim Fulton wrote:
> | >>Garrett Smith wrote:
> | >>
> | >>>Rather than leave aliases around forever, is there a utlity (or other
> | >>>means) one can use to update references to renamed/moved classes in
> | >>>the ZODB?
> | >>
> | >>Not currently. We'd like a cleaner mechanism, but haven't come up
> | >>with one yet.
>
> | >So I take it this is non-trivial. I was hoping it would boil down to a
> | >search-and-release in the Data.fs.
> |
> | It depends on what "this" is. One could fairly straightforwardly
> | write a script that could convert an off-line database. I think we
> | really want to be able to do this without taking the database off-line.
>
> I tried to do this as a step to solve a problem I had about two weeks
> ago. It didn't work, though.
>
> #!/usr/bin/python2.3 -i
>
> from ZODB import FileStorage, DB
> storage = FileStorage.FileStorage( 'Data.fs' )
> db = DB(storage)
> conn = db.open()
> root = conn.root()
> app = root['Application']
>
> import zwiki, zwiki.wiki
> # setup the alias for the initial load
> sys.modules['zope.app.wiki'] = zwiki
This was too late.
> the_wiki = app.data['the_wiki']
> the_wiki.__class__ = zwiki.wiki.Wiki
This isn't necessary. It would have gotten the new class
via the alias.
> the_wiki._p_changed = True
This is all that was needed to get the wiki object
itself written. Subobjects of the wiki object would be
unaffected.
> # save the changes:
> import transaction ; transaction.commit()
>
> The ZODB (probably pickle, actually) would complain that it didn't
> like the object. I think it is because I changed the class, so some
> sanity check failed.
No, it's because you set the alias too late.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list