[Zope-dev] ZODB: interface for walking object graph?

Andrew M. Kuchling akuchlin@mems-exchange.org
Thu, 23 Mar 2000 16:07:17 -0500 (EST)


I'd like a way to find all instances of a given class in a ZODB.  (In
ODBMS jargon, this feature seems to be called "class extents".)  The
purpose is to handle changes to a class that require rearranging; you
can do it lazily in a __setstate__ method, but after you've had 10
changes, that __setstate__ will be really complicated.  And you can
never simplify it, because you never know if there's a version 1
object hiding somewhere that just hasn't been accessed yet.  Instead,
I'd like to do it eagerly; write a script that loops over all the
instances of class C, make a change to all of them, and then commit.

I only see one way of doing this, by walking over the whole object
graph starting from the ZODB's root objects.  Storage objects do this
in their pack() method to determine reachability.  Problem: you'd have
to copy the walking logic out of the pack() method into your own
method.

Proposal: expose some interface allowing clients of a Connection
to run a function over every single object in a ZODB.  It'd be like
os.path.walk(), except over objects, not directories and files.

This means unpickling *every* *single* object in the ZODB (and sending
them all over the wire if you're using ZEO).  Inefficient, but there
seems no other alternative, and you wouldn't do this very often.

Jim, what's your reaction?

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
Somehow the people who do as they please seem to get along just about as well
as those who are always trying to please others.
    -- Bob Edwards