Can't save PFG Mailer Adapter: Compilation failed exceptions.AttributeError: 'NoneType' object has no attribute 'rfind'

Plone 4.3.15 site with PloneFormGen 1.7.23 (latest of both).
If I go to a default Mailer Adapter and simply Edit, then Save (without changing anything), it refuses to save and gives an error in the portalMessage viewlet "Please correct the indicated errors." It shows the Template tab and right above the textare for the template is this message:

Compilation Failed

exceptions.AttributeError: 'NoneType' object has no attribute 'rfind'

This happens even in a brand new Plone site, brand new Form Folder, brand new Mailer Adaptor, and without changing anything before saving.

This is the default template just to save you from looking it up, but I have a feeling the error is coming from somewhere else:

<html xmlns="http://www.w3.org/1999/xhtml">

  <head><title></title></head>

  <body>
    <p tal:content="here/getBody_pre | nothing" />
    <dl>
        <tal:block repeat="field options/wrappedFields | nothing">
            <dt tal:content="field/fgField/widget/label" />
            <dd tal:content="structure python:field.htmlValue(request)" />
        </tal:block>
    </dl>
    <p tal:content="here/getBody_post | nothing" />
    <pre tal:content="here/getBody_footer | nothing" />
  </body>
</html>

Thanks for any suggestions!

I would start by finding where that "Compilation Failed" message comes from (Products.TemplateFields?) and see if you can get a real traceback.

Thanks for the tip. Here is the tail of the traceback of where the exception actually happens. AFAICT, self here is <PageTemplate None>, because we are being called from inside __init__() (and besides, this is a TTW template, not a file).

  /usr/local/plone-4.3/buildout-cache/eggs/Products.CMFFormController-3.0.8-py2.7.egg/Products/CMFFormController/FSControllerValidator.py(58)__call__()
-> result = FSControllerValidator.inheritedAttribute('__call__')(self, *args, **kwargs)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.CMFFormController-3.0.8-py2.7.egg/Products/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.CMFCore-2.2.10-py2.7.egg/Products/CMFCore/FSPythonScript.py(127)__call__()
-> return Script.__call__(self, *args, **kw)
  /usr/local/plone-4.3/buildout-cache/eggs/Zope2-2.13.26-py2.7.egg/Shared/DC/Scripts/Bindings.py(322)__call__()
-> return self._bindAndExec(args, kw, None)
  /usr/local/plone-4.3/buildout-cache/eggs/Zope2-2.13.26-py2.7.egg/Shared/DC/Scripts/Bindings.py(359)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.PythonScripts-2.13.2-py2.7.egg/Products/PythonScripts/PythonScript.py(344)_exec()
-> result = f(*args, **kw)
  /usr/local/plone-4.3/zeoserver/Script (Python)(6)validate_base()
  /usr/local/plone-4.3/buildout-cache/eggs/Products.Archetypes-1.9.17-py2.7.egg/Products/Archetypes/BaseObject.py(487)validate()
-> errors=errors, data=data, metadata=metadata)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.Archetypes-1.9.17-py2.7.egg/Products/Archetypes/Schema/__init__.py(606)validate()
-> REQUEST=REQUEST)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.Archetypes-1.9.17-py2.7.egg/Products/Archetypes/Field.py(345)validate()
-> res = self.validate_validators(value, instance, errors, **kwargs)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.Archetypes-1.9.17-py2.7.egg/Products/Archetypes/Field.py(358)validate_validators()
-> field=self, **kwargs)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.validation-2.0.2-py2.7.egg/Products/validation/chain.py(136)__call__()
-> result = validator(value, *args, **kwargs)
  /usr/local/plone-4.3/buildout-cache/eggs/Products.TemplateFields-1.2.5-py2.7.egg/Products/TemplateFields/validators.py(98)__call__()
-> pt.write(value)
  /usr/local/plone-4.3/buildout-cache/eggs/zope.pagetemplate-3.6.3-py2.7.egg/zope/pagetemplate/pagetemplate.py(162)write()
-> self._cook()
  /usr/local/plone-4.3/buildout-cache/eggs/zope.pagetemplate-3.6.3-py2.7.egg/zope/pagetemplate/pagetemplate.py(209)_cook()
-> source_file, self._text, pt_engine, self.content_type)
  /usr/local/plone-4.3/buildout-cache/eggs/five.pt-2.2.4-py2.7.egg/five/pt/engine.py(132)cook()
-> encoding='utf-8', extra_builtins=cls.extra_builtins,
  /usr/local/plone-4.3/buildout-cache/eggs/Chameleon-3.1-py2.7.egg/chameleon/zpt/template.py(185)__init__()
-> super(PageTemplate, self).__init__(body, **config)
  /usr/local/plone-4.3/buildout-cache/eggs/Chameleon-3.1-py2.7.egg/chameleon/template.py(116)__init__()
-> self.write(body)
  /usr/local/plone-4.3/buildout-cache/eggs/Chameleon-3.1-py2.7.egg/chameleon/template.py(209)write()
-> self.cook(body)
  /usr/local/plone-4.3/buildout-cache/eggs/Chameleon-3.1-py2.7.egg/chameleon/template.py(145)cook()
-> digest = self.digest(body, names)
  /usr/local/plone-4.3/buildout-cache/eggs/Chameleon-3.1-py2.7.egg/chameleon/zpt/template.py(297)digest()
-> hex = super(PageTemplate, self).digest(body, names)
> /usr/local/plone-4.3/buildout-cache/eggs/Chameleon-3.1-py2.7.egg/chameleon/template.py(247)digest()
-> digest = os.path.splitext(self.filename)[0] + '-' + digest
(Pdb) self
<PageTemplate None>
(Pdb) self.filename
(Pdb) os.path.splitext(self.filename)
*** AttributeError: 'NoneType' object has no attribute 'rfind'

I'd guess that there's some sort of problem between Chameleon and Products.TemplateFields. Not too surprising given that Chameleon wasn't an option when that package was created.

Yup, I can reproduce it by installing a clean Plone buildout + PloneFormGen + five.pt.

Changing the condition from

        if self.filename is not BaseTemplate.filename:
            digest = os.path.splitext(self.filename)[0] + '-' + digest

to

        if self.filename and self.filename is not BaseTemplate.filename:
            digest = os.path.splitext(self.filename)[0] + '-' + digest

seems to fix the problem, but I don't know if it's just masking it.