Moving schema files to new directory..?

So I have my Python schema files in the top-level of my package and I've decided I want to move them into a content folder. I've successfully managed to migrate the portal_types, however is it possible to change the classes for objects created before the files were moved..? I have not changed anything else except for moving the files to a new directory.

So, for example, this is how my current object is referenced:
<class 'some.package.accounts.Accounts'>
...and I want it to be:
<class 'some.package.content.accounts.Accounts'>

I know I can import the class from the schema file in the new directory and set it, however this doesn't seem to be persistent and I'm not sure how to store this value?

Here's my reference:

All help would be great!

In order for the class to persist you have to detach and reattach the object from the ZODB, something like.

parent._delOb(obj_id)
obj.__class__ = NewClass
parent._setOb(obj_id, obj)

I migrated several hundred thousands of objects from Archetype to Dexterity with this method.

For your use case, anyway, you can also add some compatibility code, like plone.app.upgrade is doing:

Worth to mention, since that article and the thread you linked above I also found out that Gocept developed this product https://pypi.org/project/zodbupdate/.

You may want to check it out because they really know how to handle a ZODB.

1 Like

I used this several times with a custom Zope3 application where we don't have GS and upgrade steps. I never had any problems with migrated content objects when I used it.

1 Like

the easiest way is to do something like this:

you avoid having to have an upgrade step, but should be a good idea to do so.

Plone Foundation Code of Conduct