<br><div><span class="gmail_quote">On 6/8/07, <b class="gmail_sendername">Alek Kowalczyk</b> &lt;<a href="mailto:thealx@poczta.onet.pl">thealx@poczta.onet.pl</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Alek Kowalczyk &lt;thealx@...&gt; writes:<br><br>&gt;<br>&gt; Hi,<br>&gt; I moved my content class from mypackage.mymodule.MyContentClass into<br>&gt; mypackage.mysubpackage.mymodule.MyContentClass.<br>&gt; But when started Zope and went to visit an object I have previously created (of
<br>&gt; MyContentClass), I get:<br>&gt; ComponentLookupError: ((&lt;persistent broken mypackage.mymodule.MyContentClass<br>&gt; instance &#39;\x00\x00\x00\x00\x00\x00\x02q&#39;&gt;,<br>&gt; &lt;zope.publisher.browser.BrowserRequest
 instance <br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I found a quite well working solution on<br><a href="http://mail.zope.org/pipermail/zodb-dev/2006-September/010382.html">
http://mail.zope.org/pipermail/zodb-dev/2006-September/010382.html</a><br><br>There was only one issue: this solution assumes that we have given a DB, while<br>Zope evolve method receives already open connection. Unfortunately classFactory
<br>from DB is cached in Connection&#39;s private fields in constructor.<br>Because of that I could not assign my custom &#39;renaming&#39; class factory using:<br><br>def evolve(context): #won&#39;t work!<br>&nbsp;&nbsp;&nbsp;&nbsp;context.connection.db
().classFactory = myClassFactory<br><br>Instead I had to do some dirty private fields substitution in Connection&#39;s<br>ObjectReader:<br><br>def evolve(context): #this works nice<br>&nbsp;&nbsp;&nbsp;&nbsp;context.connection._reader._factory
 = myClassFactory</blockquote><div><br>I shouldn&#39;t announce success too early. The solution works but only during first Zope run (i.e just after evolving the schema). <br>Although classFactory returns proper class during evolve, the new class name is not saved in ZoDB, so after next unghosting object get old class names again.
<br><br></div>Here is my evolve script. I really don&#39;t know what more should I do to make Zope/ZoDB write the new class name in ZoDB. Can someone help me a bit... :) ?<br><br>def convertingClassFactory(connection, moduleName, globalName):
<br>&nbsp;&nbsp;&nbsp; #convert class name to new one and return the class object<br><br>def evolve(context):<br>&nbsp;&nbsp;&nbsp; #dirty hack to substitute classFactory<br>&nbsp;&nbsp;&nbsp; context.connection._reader._factory = convertingClassFactory<br>&nbsp;&nbsp;&nbsp; root = 
context.connection.root().get(ZopePublication.root_name, None)<br>&nbsp;&nbsp;&nbsp; for object in findObjectsMatching(root, lambda x: True):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if hasattr(object, &#39;_p_activate&#39;):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object._p_activate()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object._p_changed = True
<br><br></div>