plone / Products.CMFPlone

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

WrongType for logo when saving site control panel migrated to 5.2. #3172

Closed mauritsvanrees closed 3 years ago

mauritsvanrees commented 4 years ago

The site logo is missing a migration from ASCII to Bytes. In Plone 5.1, the site logo is of type ASCII, in 5.2 this was changed to Bytes, see commit 11482a2d37b9ded04d517bd1e9f50e234e3b3b46.

zope.schema.ASCII inherits from NativeString, which on Python 2 is the same as Bytes. On Python 3, ASCII is the same as String. Problem with a site started at 5.1 and migrated to 5.2 Py 3, is that the portal_registry reports that plone.site_logo is an ASCII type and its value is text (native Py3 string), but the ISiteSchema expects a Bytes field. Validation fails with:

zope.schema._bootstrapinterfaces.WrongType: (b'filenameb64:...', <class 'str'>, 'value')

What I did:

Alternatively:

What I expect to happen:

The logo is saved, and used as logo.

What actually happened:

Traceback:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 364, in publish_module
  Module ZPublisher.WSGIPublisher, line 267, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 68, in call_object
  Module plone.z3cform.layout, line 63, in __call__
  Module plone.z3cform.layout, line 47, in update
  Module plone.z3cform.fieldsets.extensible, line 65, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 145, in update
  Module plone.app.z3cform.csrf, line 22, in execute
  Module z3c.form.action, line 98, in execute
  Module z3c.form.button, line 315, in __call__
  Module z3c.form.button, line 170, in __call__
  Module plone.app.registry.browser.controlpanel, line 63, in handleSave
  Module z3c.form.group, line 114, in applyChanges
  Module z3c.form.form, line 51, in applyChanges
  Module z3c.form.datamanager, line 91, in set
  Module plone.registry.recordsproxy, line 60, in __setattr__
  Module plone.registry.registry, line 51, in __setitem__
  Module plone.registry.record, line 82, in _set_value
  Module zope.schema._bootstrapfields, line 292, in validate
  Module zope.schema._field, line 227, in _validate
  Module zope.schema._bootstrapfields, line 495, in _validate
  Module zope.schema._bootstrapfields, line 338, in _validate
zope.schema._bootstrapinterfaces.WrongType: (b'filenameb64:S2Vlb3BfRXhwbG9yaW5nLnBuZw==;datab64:iV...
...ORK5CYII=', <class 'str'>, 'value')

What version of Plone/ Addons I am using:

Solution:

I have not tried solutions yet, but I can imagine:

I do not expect that all ASCII records should be turned into Bytes. It seems this should be determined on a field-by-field basis. But I do wonder if a fix could be made more general: go through all registry records and check if the record type matches the interface.

mauritsvanrees commented 3 years ago

Long comment. Summary is at the end.

The site for which I originally reported this problem, now has a related problem that is caused by my PR. After the upgrade, the site logo disappears.

After some tests, I see that this is specific for this site, because I copied the code of my PR to a custom package and ran it, and now it goes wrong when I update to Plone 5.2.3. But I see ways where others may get the same problem. Also: editing the logo via the portal_registry no longer works.

Let's see if I can reproduce this in core Plone.

So 5.1 to 5.2 on Python 2 mostly works. The site logo is okay, as long as you only edit it in the site-controlpanel, not in portal_registry.

Now we try Python 3:

For more fun, I notice an extra problem, where my PR is innocent:

Summary:

mauritsvanrees commented 3 years ago

I close this one as my PR is merged. For the configuration registry editor problem I opened a new issue: https://github.com/plone/Products.CMFPlone/issues/3215