[ZODB-Dev] ExportImport.py: failing on import of extension class

Jim Fulton jim at zope.com
Thu Apr 26 10:51:55 EDT 2007


On Apr 26, 2007, at 10:44 AM, Paul Winkler wrote:

> On Thu, Apr 26, 2007 at 10:10:17AM -0400, Jim Fulton wrote:
>> On Apr 26, 2007, at 2:13 AM, Paul Winkler wrote:
>>
>>> In ExportImport._importDuringCommit() I found this little gem:
>>>
>>>            pfile = StringIO(data)
>>>            unpickler = Unpickler(pfile)
>>>            unpickler.persistent_load = persistent_load
>>>
>>>            newp = StringIO()
>>>            pickler = Pickler(newp, 1)
>>>            pickler.persistent_id = persistent_id
>>>
>>>            pickler.dump(unpickler.load())
>>>            pickler.dump(unpickler.load())
>>>            data = newp.getvalue()
>>>
>>>
>>> What's with the two load-and-dump lines near the end?
>>
>> It is transforming the pickles by assigning new object ids to the
>> objects imported.
>> The unpickler unpickles the pickles into an internal format that can
>> be creates without actually creating the original objects.  It
>> collects object ids and reassigns them. The pickler then turns the
>> internal data back into pickles with the new object ids.
>> This is done in 2 steps because database records consist of 2
>> pickles.  The first has enough information to create a ghost. The
>> second pickle contains the object state.
>
> Ah, thanks! So that means my import is succeeding with the ghost
> and failing on object state.
>
> Any ideas how to troubleshoot the failure in copy_reg.__newobj__?
> Why is a pickle of an old-style extension class getting run through
> copy_reg.__newobj__() which only works on new-style classes?

Old-style extension classes become new-style classes in Zope 2.8 and  
later.  Extension Classes *are* new stype classes in Zope 2.8 and  
beyond.

Jim


--
Jim Fulton			mailto:jim at zope.com		Python Powered!
CTO 				(540) 361-1714			http://www.python.org
Zope Corporation	http://www.zope.com		http://www.zope.org





More information about the ZODB-Dev mailing list