Improper indexing of UID of DX content

As part of a migration to Plone 5.0 we encounter the following misbehaviour:

A standard Plone Folder

>>> doc = app.restrictedTraverse('/share_20171025-144751/hrz')
>>> doc.portal_type
'Folder'
>>> doc.__class__
<class 'plone.app.contenttypes.content.Folder'>
>>> doc.UID
'1eda85a66b1c919616f2ad88649952e2'

has the given UID (which is assigned by the migration process to the created folder in order to retain the original UID (because of existing links in RichText fields).

However this folder is object in portal_catalog with a completely different UID:

We assign the "old" UID like this in our migration script:

folder = plone.api.content.create(...)
folder.UID = old_uid    # 1eda85a66b1c919616f2ad88649952e2
folder.reindexObject()

So assigning a new UID does not seem to override the original UID of the freshly created
folder...am I missing something?

-aj

The UID may not be where you expect it to be.

I would check which UUID this function is returning:

from plone.uuid.interfaces import IUUID
IUUID(obj)

In some migrations I had to use this code to fix the UID:

setattr(self.new, '_plone.uuid', getattr(self.old, '_at_uid'))

Yeah, I figured that also out. Somewhere I found a method with explicit getter and setter() methods for the UID property. But plone.uuid is king here.

-aj