Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analytics viewlet breaks if registry record is not defined #227

Closed
ale-rt opened this issue Dec 16, 2019 · 6 comments · Fixed by #228 or #229
Closed

analytics viewlet breaks if registry record is not defined #227

ale-rt opened this issue Dec 16, 2019 · 6 comments · Fixed by #228 or #229

Comments

@ale-rt
Copy link
Member

ale-rt commented Dec 16, 2019

After #220 the fallback of returning an empty string if the webstat_js record was not found was removed.

That causes a rendering error:

zope.location.interfaces.LocationError: zope.location.interfaces.LocationError: (<Products.Five.browser.metaconfigure.View object at 0x7febfad14c50>, 'webstats_js')

 - Expression: "view/webstats_js"
 - Filename:   ... ayout-3.4.0-py3.7.egg/plone/app/layout/analytics/view.pt
 - Location:   (line 3: col 17)
 - Source:     tal:condition="view/webstats_js"
                              ^^^^^^^^^^^^^^^^
@ale-rt
Copy link
Member Author

ale-rt commented Dec 16, 2019

ale-rt added a commit that referenced this issue Dec 16, 2019
Restore compatibility with old code that was inheriting from this class and overriding the __init__ method

Fixes #227
Refs #220
@mauritsvanrees
Copy link
Member

This is still broken on coredev 5.2:

  • Create a fresh Plone 5.2 site.
  • View the front page and you see a traceback in the log.
  • Go to the site control panel and add content to the webstats_js: no more traceback.
  • Empty the webstats_js: traceback is back.
2020-02-05 16:43:18,785 ERROR   [plone.app.viewletmanager:118][waitress] Error while rendering viewlet-manager=plone.portalfooter, viewlet=plone.analytics
Traceback (most recent call last):
  File "/Users/maurits/shared-eggs/cp27m/plone.app.viewletmanager-3.1.0-py2.7.egg/plone/app/viewletmanager/manager.py", line 110, in render
    html.append(viewlet.render())
  File "/Users/maurits/shared-eggs/cp27m/Zope-4.1.3-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 126, in __call__
    return self.__func__(__self__, *args, **kw)
  File "/Users/maurits/shared-eggs/cp27m/Zope-4.1.3-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 61, in __call__
    sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  File "/Users/maurits/shared-eggs/cp27m/zope.pagetemplate-4.4.1-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 135, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations
  File "/Users/maurits/shared-eggs/cp27m/Zope-4.1.3-py2.7.egg/Products/PageTemplates/engine.py", line 88, in __call__
    return self.template.render(**kwargs)
  File "/Users/maurits/shared-eggs/cp27m/z3c.pt-3.2.0-py2.7.egg/z3c/pt/pagetemplate.py", line 173, in render
    return base_renderer(**context)
  File "/Users/maurits/shared-eggs/cp27m/Chameleon-3.6.2-py2.7.egg/chameleon/zpt/template.py", line 306, in render
    return super(PageTemplate, self).render(**_kw)
  File "/Users/maurits/shared-eggs/cp27m/Chameleon-3.6.2-py2.7.egg/chameleon/template.py", line 209, in render
    raise_with_traceback(exc, tb)
  File "/Users/maurits/shared-eggs/cp27m/Chameleon-3.6.2-py2.7.egg/chameleon/template.py", line 187, in render
    self._render(stream, econtext, rcontext)
  File "/Users/maurits/community/plone-coredev/5.2/var/cache/8b517186501544b2072bbb30bc6d18a3.py", line 95, in render
    __condition = _static_4651129680(getitem('view'), econtext, True, ('webstats_js', ))
  File "/Users/maurits/shared-eggs/cp27m/Zope-4.1.3-py2.7.egg/Products/PageTemplates/expression.py", line 94, in __call__
    base = self.traverse(base, request, path_items)
  File "/Users/maurits/shared-eggs/cp27m/Zope-4.1.3-py2.7.egg/Products/PageTemplates/expression.py", line 65, in traverse
    base, name, path_items[i:], request=request
  File "/Users/maurits/shared-eggs/cp27m/zope.traversing-4.3.1-py2.7.egg/zope/traversing/adapters.py", line 156, in traversePathElement
    return traversable.traverse(nm, further_path)
  File "/Users/maurits/shared-eggs/cp27m/zope.traversing-4.3.1-py2.7.egg/zope/traversing/adapters.py", line 61, in traverse
    raise LocationError(subject, name)
LocationError: (<Products.Five.viewlet.metaconfigure.AnalyticsViewlet object at 0x11776dcd0>, 'webstats_js')

 - Expression: "view/webstats_js"
 - Filename:   ... /src/plone.app.layout/plone/app/layout/analytics/view.pt
 - Location:   (line 3: col 17)
 - Source:     tal:condition="view/webstats_js"
                              ^^^^^^^^^^^^^^^^
 - Arguments:  repeat: {...} (0)
               template: <ViewPageTemplateFile - at 0x113decbd0>
               views: <ViewMapper - at 0x11776df10>
               modules: <_SecureModuleImporter - at 0x10d637dd0>
               args: <tuple - at 0x10badf050>
               here: <ImplicitAcquisitionWrapper Plone at 0x115e01870>
               wrapped_repeat: <SafeMapping - at 0x117347440>
               user: <ImplicitAcquisitionWrapper - at 0x113db5b40>
               nothing: <NoneType - at 0x10b9f5718>
               container: <ImplicitAcquisitionWrapper Plone at 0x115e01870>
               request: <WSGIRequest - at 0x1177f3e10>
               traverse_subpath: <list - at 0x1172a4ef0>
               default: <object - at 0x10bb40e20>
               context: <ImplicitAcquisitionWrapper Plone at 0x115e01870>
               view: <AnalyticsViewlet plone.analytics at 0x11776dcd0>
               translate: <function translate at 0x1177cf230>
               root: <ImplicitAcquisitionWrapper  at 0x115e1b320>
               options: {...} (0)
               loop: {...} (0)
               target_language: <NoneType - at 0x10b9f5718>

Maybe update needs to be called before this line in plone.app.viewletmanager. But then why does it work when webstats_js has content?

@mauritsvanrees mauritsvanrees reopened this Feb 5, 2020
@ale-rt
Copy link
Member Author

ale-rt commented Feb 5, 2020

Reverting this line should fix the issue:

Anyway the sweetest thing would be making webstats_js a memoized property (thus lazy loading it only when needed without relying on update being called), but I feared at the time it was a breaking change.

@ale-rt
Copy link
Member Author

ale-rt commented Feb 5, 2020

I will try to investigate more and make a PR in the evening

@mauritsvanrees
Copy link
Member

Making it a method should be enough I think, with @property. And instead of memoize it is easier to do a tal:define="webstats_js view/webstats_js" and then use webstats_js in the tal condition and content.

@ale-rt
Copy link
Member Author

ale-rt commented Feb 6, 2020

Funny enough yesterday I got a PR (plone/plone.app.testing#64) failing for this reason: https://jenkins.plone.org/job/pull-request-5.2-3.7/842/console

ale-rt added a commit that referenced this issue Feb 6, 2020
Analytics viewlet: make webstats_js a property, so that it does not rely on an a call to the update method to be correctly evaluated

Fixes #227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants