Repository navigation
Closed
Description
chameleon.template.BaseTemplate.digest() prepends the pathname (minus extension) to the digest under this condition:
if self.filename is not BaseTemplate.filename:
digest = os.path.splitext(self.filename)[0] + '-' + digest
However, when self is <PageTempate None> this throws the following error:
*** AttributeError: 'NoneType' object has no attribute 'rfind'
This happens in the following scenario:
- Install a clean Plone 4.3.15 buildout
- Add Products.PloneFormGen 1.7.23 to the buildout
- Add five.pt to the buildout
- Create a new Plone site, activate PloneFormGen
- Create a FormFolder
- Go to the
mailerMail Adapter which is added by default to a new Form Folder - Edit the
mailer - Save it without making any changes
Result: You will not be able to save. The following validation error for the textarea containing the default mail template is displayed:
Compilation Failed
exceptions.AttributeError: 'NoneType' object has no attribute 'rfind'
I'm not sure if there is something that PloneFormGen needs to do differently, but I do know that changing the condition to this fixed the problem:
if self.filename and self.filename is not BaseTemplate.filename:
Is self = <PageTemplate None> because we are being called from __init__()? Either way, this is a TTW template, so it should not have a filename.
This is the tail of the stack where the error happens:
/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'
Reacted by Alin Voinea
Metadata
Metadata
Assignees
Labels
No labels
Activity
jamadden commentedon Oct 31, 2017
I ran into the same thing with z3c.ptcompat. We worked around it there.
fulv commentedon Nov 5, 2017
So I can see three possible solutions for this:
1. In
Products.TemplateFields.validators.ZPTValidator.__call__The symbol
ptis bound to a newAqPageTemplate, which is aProducts.PageTemplates.PageTemplate.PageTemplate:Before the
writecall, we could setpt.pt_source_fileto a callable that returns any string value, e.g.:This seems risky to me, but it could be wrapped in an
if not pt.pt_source_file(). Also, I can't find the repository forProducts.TemplateFields.2. In
five.pt.engine.Program.cook:130:Basically do what @jamadden did in z3c.ptcompat, and change
filename=source_filetofilename=source_file or '<string>'.This seems safe.
3. In
chameleon.template.BaseTemplate.digest(), what I suggested above:change
to
I think 3 should be done anyway.
fulv commentedon Nov 5, 2017
@jensens do you know where Products.TemplateFields lives?
jensens commentedon Nov 6, 2017
@fulv if nobody migrated it to git, it should be transferred to GitHub collective from here https://svn.plone.org/svn/archetypes/Products.TemplateFields/
malthe commentedon Nov 6, 2017
Can't we do without a change in
Products.TemplateFields– ?malthe commentedon Nov 6, 2017
@fulv – wanna make a PR?
fulv commentedon Nov 6, 2017
@malthe - sure.
@jensens - would you please remind me what qualifies for the collective GitHub org vs the plone org?
jensens commentedon Nov 6, 2017
@fulv, the code in archetypes svn never required a signed contributor agreement, so it can't go into plone organization, where it is required.
fulv commentedon Nov 6, 2017
rafaelbco commentedon Jan 23, 2018
Any news on this? I've just stumbled upon this bug.
fulv commentedon Jan 23, 2018
fredvd commentedon Oct 10, 2019
Fix for Plone 4.3 with PloneFormGen / Products.Templatefields and five.pt with newer Chameleon 3.0: https://github.com/zestsoftware/five.pt/tree/2.2
Cross-ported the fix from z3c.ptcompat from @jamadden found here https://github.com/zopefoundation/z3c.ptcompat/pull/4/files