TransformError when saving items with richtext fields [resolved]

I just upgraded a site from 5.1a to 5.1b4
Now I get a transform error when I try to save changes to richtext fields.
I also cannot create new news items or pages without getting the same transform error.

TransformError: Error during transformation

 - Expression: "python:context.text.output_relative_to(view.context)"
 - Filename:   ... egg/plone/app/contenttypes/browser/templates/newsitem.pt
 - Location:   (line 15: col 29)
 - Source:     ... ucture python:context.text.output_relative_to(view.context)"
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I can't replicate the error on a brand new 5.1b4 site so it's likely something I introduced, just not sure where to look.

I noriced a few weird things in 5.1b4, but since I could not get it to work without installing Mosaic, I decided to wait for the next release..

Anyway: Portal transform did not work as before, some Markdown transforms did not work ( it rendered the code and not 'markdown => html'.

I notice that I have commented out 'your line' in one of my templates (can't remember why) and changed it to

structure context/text/output"

Well Plone 5.1b4 works out of the box for me. The problem is upgrading from an older 5.1x.

I think you traced it to output_relative_to which is apparently a "trick" to ensure rich text fields resolve properly when your Plone site is not served from the root of the domain. See issue discussed here:

Does both sites use the same "base url":

http://localhost:8080/oldsite/someitem
http://localhost:8080/addedinplone5/somenewsitem

(taken from memory, but I have a feeling that the "relative stuff" was calculated from zope root instead of plone root or something (PS: I tested it with lineage, so it could be a lineage problem)

Update: ... the above answer came while I was typing.....

A bit more background. Visiting a dexterity type that uses richtext was returning the following error:

Rendering error
 - Expression: "context/content/text/output"
 - Location:   (line 22: col 46)

At first I thought the solution was to just reimport the HTML Output Filters

portal_setup > import > HTML Output Filters > Import all steps

Running my instance in foreground mode I saw the following output, even after the reimport.

2017-09-06 13:16:39 ERROR portlets Error while rendering <plone.app.portlets.manager.ColumnPortletManagerRenderer object at 0x7f0d96b42b50>
Traceback (most recent call last):
  File "/home/ubuntu/workspace/eggs/Products.PloneFormGen-1.8.2-py2.7.egg/Products/PloneFormGen/patches.py", line 21, in safe_render
    return portlet_renderer.render()
  File "/home/ubuntu/workspace/eggs/Zope2-2.13.26-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 125, in __call__
    return self.im_func(im_self, *args, **kw)
  File "/home/ubuntu/workspace/eggs/Zope2-2.13.26-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 59, in __call__
    sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  File "/home/ubuntu/workspace/eggs/zope.pagetemplate-4.2.1-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 137, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations
  File "/home/ubuntu/workspace/eggs/five.pt-2.2.4-py2.7.egg/five/pt/engine.py", line 98, in __call__
    return self.template.render(**kwargs)
  File "/home/ubuntu/workspace/eggs/z3c.pt-3.0.0a1-py2.7.egg/z3c/pt/pagetemplate.py", line 163, in render
    return base_renderer(**context)
  File "/home/ubuntu/workspace/eggs/Chameleon-2.25-py2.7.egg/chameleon/zpt/template.py", line 261, in render
    return super(PageTemplate, self).render(**vars)
  File "/home/ubuntu/workspace/eggs/Chameleon-2.25-py2.7.egg/chameleon/template.py", line 191, in render
    raise_with_traceback(exc, tb)
  File "/home/ubuntu/workspace/eggs/Chameleon-2.25-py2.7.egg/chameleon/template.py", line 171, in render
    self._render(stream, econtext, rcontext)
  File "19af01d3e14b86bc058cc867486ec20a.py", line 320, in render
  File "/home/ubuntu/workspace/eggs/five.pt-2.2.4-py2.7.egg/five/pt/expressions.py", line 161, in __call__
    return base()
  File "/home/ubuntu/workspace/eggs/plone.portlet.static-3.1.1-py2.7.egg/plone/portlet/static/static.py", line 183, in transformed
    context=transformer_context, mimetype='text/html')
  File "/home/ubuntu/workspace/eggs/Products.PortalTransforms-3.0.0-py2.7.egg/Products/PortalTransforms/TransformEngine.py", line 171, in convertTo
    usedby=usedby, **kwargs)
  File "/home/ubuntu/workspace/eggs/Products.PortalTransforms-3.0.0-py2.7.egg/Products/PortalTransforms/chain.py", line 45, in convert
    data = transform.convert(orig, data, **kwargs)
  File "/home/ubuntu/workspace/eggs/Products.PortalTransforms-3.0.0-py2.7.egg/Products/PortalTransforms/Transform.py", line 196, in convert
    return self._v_transform.convert(*args, **kwargs)
  File "/home/ubuntu/workspace/eggs/Products.PortalTransforms-3.0.0-py2.7.egg/Products/PortalTransforms/transforms/safe_html.py", line 2560, in convert
    safe_html = self.scrub_html(orig)
  File "/home/ubuntu/workspace/eggs/Products.PortalTransforms-3.0.0-py2.7.egg/Products/PortalTransforms/transforms/safe_html.py", line 2605, in scrub_html
    style=False)
  File "/home/ubuntu/workspace/eggs/lxml-2.3-py2.7-linux-x86_64.egg/lxml/html/clean.py", line 204, in __init__
    "Unknown parameter: %s=%r" % (name, value))
TypeError: Unknown parameter: safe_attrs=['rev', 'prompt', 'color', 'colspan', 'accesskey', 'usemap', 'cols', 'accept', 'datetime', 'char', 'accept-charset', 'shape', 'href', 'hreflang', 'selected', 'type', 'alt', 'nowrap', 'id', 'axis', 'compact', 'rows', 'checked', 'for', 'start', 'hspace', 'charset', 'ismap', 'label', 'target', 'method', 'readonly', 'rel', 'scope', 'size', 'cite', 'media', 'multiple', 'src', 'nohref', 'action', 'rowspan', 'abbr', 'span', 'height', 'class', 'enctype', 'disabled', 'name', 'charoff', 'clear', 'summary', 'value', 'longdesc', 'headers', 'vspace', 'noshade', 'coords', 'width', 'maxlength', 'title', 'align', 'dir', 'tabindex', 'style']

The error seemed to be coming from lxml

Module lxml.html.clean, line 204, in __init__
TypeError: Unknown parameter: safe_attrs=['rev', 'prompt', 'color', 'colspan', 'accesskey', 'usemap', 'cols', 'accept', 'datetime', 'char', 'accept-charset', 'shape', 'href', 'hreflang', 'selected', 'type', 'alt', 'nowrap', 'id', 'axis', 'compact', 'rows', 'checked', 'for', 'start', 'hspace', 'charset', 'ismap', 'label', 'target', 'method', 'readonly', 'rel', 'scope', 'size', 'cite', 'media', 'multiple', 'src', 'nohref', 'action', 'rowspan', 'abbr', 'span', 'height', 'class', 'enctype', 'disabled', 'name', 'charoff', 'clear', 'summary', 'value', 'longdesc', 'headers', 'vspace', 'noshade', 'coords', 'width', 'maxlength', 'title', 'align', 'dir', 'tabindex', 'style']

It turns out that my buildout was pinning old stuff, for example lxml was pinned to lxml 2.3
In the end I commented out most pins in the [versions] section of my buildout.cfg file then reran buildout.

Looking through http://dist.plone.org/release/5.1b4/versions.cfg it turns out that lxml is pinned to 3.7.3 so that fixed that.

Plone Foundation Code of Conduct