plone / Products.CMFPlone

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

Resource Registry: one missing bundle resource (jscompilation field) breaks Plone resource registry and plone-compile-resources #3096

Open fredvd opened 4 years ago

fredvd commented 4 years ago

Plone 5.2.1. I'm working on an add'on and added a new bundle with javascript to the resource registry confguration using Generic Setup and an upgrade step. When I run my upgrade step the whole Plone output breaks.

In the frontend no javascript is loaded at all, when I check the Zope log, a traceback is shown with a KeyError on the resource I had added in the jscompilation field in my new Bundle.

Traceback (most recent call last):
  File "/var/zope/.buildoutcache/eggs/Chameleon-3.6.2-py3.7.egg/chameleon/template.py", line 187, in render
    self._render(stream, econtext, rcontext)
  File "/var/zope/highcharts8-sgbp-9260/var/chameleon_cache/ff0edc12d57daf7cd00b1c3137664d46.py", line 149, in render
    __iterator = _static_140634937114064(getitem('view'), econtext, True, ('scripts', ))
  File "/var/zope/.buildoutcache/eggs/Zope-4.1.3-py3.7.egg/Products/PageTemplates/expression.py", line 101, in __call__
    return base()
  File "/var/zope/.buildoutcache/eggs/Products.CMFPlone-5.2.1-py3.7.egg/Products/CMFPlone/resources/browser/scripts.py", line 155, in scripts
    result.extend(self.ordered_bundles_result())
  File "/var/zope/.buildoutcache/eggs/Products.CMFPlone-5.2.1-py3.7.egg/Products/CMFPlone/resources/browser/resource.py", line 204, in ordered_bundles_result
    self.get_data(bundle, result)
  File "/var/zope/.buildoutcache/eggs/Products.CMFPlone-5.2.1-py3.7.egg/Products/CMFPlone/resources/browser/scripts.py", line 57, in get_data
    not bundle.last_compilation or
  File "/var/zope/.buildoutcache/eggs/Products.CMFPlone-5.2.1-py3.7.egg/Products/CMFPlone/resources/bundle.py", line 79, in last_compilation
    loc, path = self._real_path(ctx)
  File "/var/zope/.buildoutcache/eggs/Products.CMFPlone-5.2.1-py3.7.egg/Products/CMFPlone/resources/bundle.py", line 36, in _real_path
    resource = getSite().restrictedTraverse(resource_path)
  File "/var/zope/.buildoutcache/eggs/Zope-4.1.3-py3.7.egg/OFS/Traversable.py", line 367, in restrictedTraverse
    return self.unrestrictedTraverse(path, default, restricted=True)
  File "/var/zope/.buildoutcache/eggs/Zope-4.1.3-py3.7.egg/OFS/Traversable.py", line 350, in unrestrictedTraverse
    raise e
  File "/var/zope/.buildoutcache/eggs/Zope-4.1.3-py3.7.egg/OFS/Traversable.py", line 301, in unrestrictedTraverse
    next = obj[name]
  File "/var/zope/.buildoutcache/eggs/zope.browserresource-4.3-py3.7.egg/zope/browserresource/directory.py", line 91, in __getitem__
    raise KeyError(name)
KeyError: 'viewinit.p5.min.js'

Hmm, I expect the frontend to still render, the plone.resourceregistries.script to output the remaining valid bundles and log an error, but not crash the whole Plone site (including the resourceRegistres control panel which is unusable now as well.

Following the traceback to resource/bundle.py

https://github.com/plone/Products.CMFPlone/blob/3ecbd733c97ce720f3c4644b08cc3faf2c23d0b4/Products/CMFPlone/resources/bundle.py#L30-L38

The The/Except around feching the resource only catches NotFound, but zope.browserresource is throwing a KeyError.

( Maybe the original implementation for bundling was only tested with the plone.resource (++plone++ namespace) where TTW compilations of a bundle can be stored, but not with ++resource++ locations which can only point to file system? )

fredvd commented 4 years ago

3097 Work in progress with test.