Set UID for Dexterity type

dexterity, plone

Solution

For Dexterity UUID values, the `plone.uuid` package is used. `plone.uuid` simply stores the value in a attribute.

The following suffices to set a predetermined UUID on an existing Dexterity object `obj`:

from plone.uuid.interfaces import ATTRIBUTE_NAME

setattr(obj, ATTRIBUTE_NAME, uuid)

Problem

I'm migrating content from Archetypes to Dexterity and I need the new items to have the same UID as the old ones. On Archetypes items I can call context._setUID('my-uid'). Is there something similar for Dexterity?

Original source