[ZCM] [ZC] 239/ 3 Comment "Product Re-Factoring Impossible"

Collector: Zope Bugs and Patches ... zope-coders@zope.org
Mon, 25 Feb 2002 06:57:15 -0500


Issue #239 Update (Comment) "Product Re-Factoring Impossible"
 Status Pending, Database/bug critical
To followup, visit:
  http://collector.zope.org/Zope/239

==============================================================
= Comment - Entry #3 by htrd on Feb 25, 2002 6:57 am

The old class name is Products.DotOrg.Members.MembersApp. You dont say what the new class name is, but for the sake of this example lets say it is Products.DotOrgMembers.MemberStuff.App

An easy solution is to create a reference to the new class under the original name. If you have deleted the old MembersApp.py you will need to recreate it, then add to it:

from Products.DotOrgMembers.MemberStuff import App as MembersApp

All new instances will use the new name of course. Further, all old instances will switch over to the new name as soon as they are modified and repickled. You need to keep this legacy support file around for as long as you have unmodified legacy objects in the database.



________________________________________
= Comment - Entry #2 by shane on Feb 22, 2002 1:17 pm

I started a utility to do just this a few months ago:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/zodbex/zodbex/ChangeModules/change_modules.py?rev=1.1.1.1&content-type=text/vnd.viewcvs-markup

It's not functional yet, but it's close.  I wonder if I could hand off the work to someone who knows a lot about ZODB.

________________________________________
= Request - Entry #1 by Anonymous User on Feb 21, 2002 8:11 pm

We are currently re-organizaing our code base and have existing production sites using this code base we will need to update in the future. The ZODB provides no mechanism for updating the pickled objects to refer to the new layout. After the change, any existing site returns a slew of errors such as:
 
2002-02-21T22:26:36 PROBLEM(100) ZODB Could not import class 'MembersApp' from module 'Products.DotOrg.Members.MembersApp'
 
I've read through the mailing list archives and any other docs I could find. They suggest __module_aliases__ which I've tried. It helps but doesn't work with classes which are very common. I've tried many other things like manually assigning the __class__ attribute and using a custom persistent_load() method. 
 
There either needs to be a tool for this or some documentation on massaging existing code to get the module_aliases trick to work (change class reference to module references in the pickled objects).
 
This is critically important to the long term viability of Zope and any products built on Zope. If you can't restructure your code as it grows, it eventually becomes un-maintainable. 

==============================================================