plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
254 stars 191 forks source link

WrongContainedType exception during registry.xml import. #2154

Open Gagaro opened 7 years ago

Gagaro commented 7 years ago

BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)

What I did:

Run an upgrade with a registry.xml import (this one).

What I expect to happen:

The registry is imported without issue.

What actually happened:

I got a WrongContainedType:

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.GenericSetup.tool, line 1053, in manage_doUpgrades
  Module Products.GenericSetup.upgrade, line 166, in doStep
  Module Products.CMFPlomino.upgrades, line 5, in run_registry_step
  Module Products.GenericSetup.tool, line 358, in runImportStepFromProfile
  Module Products.GenericSetup.tool, line 1245, in _doRunImportStep
   - __traceback_info__: plone.app.registry
  Module plone.app.registry.exportimport.handler, line 70, in importRegistry
  Module plone.app.registry.exportimport.handler, line 123, in importDocument
  Module plone.app.registry.exportimport.handler, line 329, in importRecord
   - __traceback_info__: record name: plone.displayed_types
  Module plone.registry.record, line 82, in _set_value
  Module zope.schema._bootstrapfields, line 183, in validate
  Module zope.schema._field, line 529, in _validate
WrongContainedType: ([WrongType(u'News Item', <type 'str'>, ''), WrongType(u'collective.alias', <type 'str'>, ''), WrongType(u'Article', <type 'str'>, ''), WrongType(u'Collection', <type 'str'>, ''), WrongType(u'Document', <type 'str'>, ''), WrongType(u'Folder', <type 'str'>, ''), WrongType(u'EduBook', <type 'str'>, ''), WrongType(u'EduChapter', <type 'str'>, ''), WrongType(u'EduParagraph', <type 'str'>, ''), WrongType(u'EduSection', <type 'str'>, ''), WrongType(u'File', <type 'str'>, ''), WrongType(u'ENLIssue', <type 'str'>, ''), WrongType(u'EasyNewsletter', <type 'str'>, ''), WrongType(u'Link', <type 'str'>, ''), WrongType(u'PlominoDatabase', <type 'str'>, ''), WrongType(u'AccessibleVideo', <type 'str'>, ''), WrongType(u'Event', <type 'str'>, '')], 'value')

What version of Plone/ Addons I am using:

Plone 5.1rc1

More information

For what I gathered, the issue comes because the expected type is str while we have unicode. The string imported from the registry.xml file are always unicode. The str type come from the vocabulary in the xml.

The type of a Choice record is supposed to be None. But when a vocabulary is defined, the type is determined from it (relevant code).

I don't remember having this issue before. I'm not sure what the right fix should be.

Gagaro commented 7 years ago

I just tested this on a completely vanilla Plone and I got a list of str instead of unicode (as I have in my other project). So I'm not sure what's wrong. I'll keep this issue updated.

Gagaro commented 7 years ago

Ok so I actually had lxml 4.0.0 on the vanilla Plone and 3.7.3 on the project one.

I updated it and I now get a str. But the values stored in the registry are still unicode so the import still fails.

1letter commented 6 years ago

A Workaround for me in the Registry, is purge the Values via Attribute.

<record
        interface="Products.CMFPlone.interfaces.IDateAndTimeSchema"
        prefix="plone"
        field ="available_timezones">
        <value purge="True">
            <element>Europe/Berlin</element>
        </value>
    </record>