Sniff, was Re: [ZODB-Dev] Copying instances between multiple storages

Christian Reis kiko@async.com.br
Tue, 21 May 2002 08:55:01 -0300


On Tue, May 21, 2002 at 11:02:03AM +0100, Toby Dickenson wrote:
> On Mon, 20 May 2002 18:50:36 -0300, Christian Reis <kiko@async.com.br>
> wrote:
> 
> >> Fair enough. So what do I have to do? Instance another object and copy
> >> it's data over (ugh)?
> 
> Thats what I would do, if your object is of small finite size.

Really? There is no clone functionality in the ZODB? I've noticed that
something has been mentioned called Mount*Storage; I'd suppose it'd do
something like that, but I haven't seen it yet.

So you suggest I just create a new instance, and iterate through the
attributes, copying them over.

> >> copy.copy/deepcopy won't help, will they?
> 
> I dont see why not. Have you tried it? Of course you can always define
> your own __copy__ and __deepcopy__ methods, and this solution has all
> the 'advantages' of your first solution.

Well, when I try to copy a persistent instance:

>>> import copy
>>> p = get_catalog("Products").dump()[0]
>>> copy.copy(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.1/copy.py", line 78, in copy
    raise error, \
copy.Error: un(shallow)copyable object of type <extension class
Domain.Product.Product at 83ccba8>

And deepcopy provides me the same error, so I probably have to define
__*copy__ if it is to work, right?

> Zope's management interface has a copy/paste facility, which uses
> ZODB's import/export feature. Beware that you may end up 'cloning' the
> whole database if your object has a reference to the root.

import/export? Is there a doc on this beyond the mailing list? Maybe I
should be a man and start a ZODB faq using faqwiz.

> > have an idea how things would work,
> >enough to give a simple "looks good/bad" answer?
> 
> A different solution would be to use application-specific handles to
> the objects in the foreign database. Zope's ZCatalog uses urls for
> this.

Yes, addressing is another problem, but it doesn't invalidate the
problems with cloning objects, since I have to support disconnected
operation (that's the gist of it, actually - I need to copy objects
between databases).

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 272 3330 | NMFL