Ticket #10875 (confirmed Bug)

Opened 6 years ago

Last modified 3 years ago

AttributeError when editing a page in Plone 4

Reported by: m_overac Owned by:
Priority: n/a Milestone: 4.x
Component: General Version: 4.1
Keywords: upstream Cc:

Description

Installing plone4 with buildout on a debian box runs without errors.I used 4.0-latest as version for plone and python version 2.6.5. Creating and editing a page results in the following error:

Traceback (innermost last):
  Module ZPublisher.Publish, line 127, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 47, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 31, in _call
  Module Shared.DC.Scripts.Bindings, line 324, in __call__
  Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
  Module Products.CMFCore.FSPageTemplate, line 240, in _exec
  Module Products.CMFCore.FSPageTemplate, line 180, in pt_render
  Module Products.PageTemplates.PageTemplate, line 80, in pt_render
  Module zope.pagetemplate.pagetemplate, line 115, in pt_render
   - Warning: Macro expansion failed
   - Warning: <type 'exceptions.KeyError'>: 'macro'
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 946, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 821, in do_loop_tal
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 522, in do_optTag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 821, in do_loop_tal
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 946, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 583, in do_setLocal_tal
  Module zope.tales.tales, line 696, in evaluate
   - URL: file:/home/systemuser/plone_sites/plone4-test/eggs/Plone-4.0rc1-py2.6.egg/Products/CMFPlone/skins/plone_templates/calendar_macros.pt
   - Line 12, Column 4
   - Expression: <PythonExpr date_components_support_view.result(inputvalue, 0, starting_year, ending_year, future_years)>
   - Names:
      {'container': <PloneSite at /Plone>,
       'context': <ATDocument at /Plone/front-page>,
       'default': <object object at 0x7f49fb818ad0>,
       'here': <ATDocument at /Plone/front-page>,
       'loop': {u'field': <Products.PageTemplates.Expressions.PathIterator object at 0x68f9810>,
                u'fieldset': <Products.PageTemplates.Expressions.PathIterator object at 0x6b2dfd0>},
       'nothing': None,
       'options': {'args': (),
                   'state': <Products.CMFFormController.ControllerState.ControllerState object at 0x60aac50>},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x6bc2838>,
       'request': <HTTPRequest, URL=http://83.169.61.97:9120/Plone/front-page/atct_edit>,
       'root': <Application at >,
       'template': <FSControllerPageTemplate at /Plone/atct_edit used for /Plone/front-page>,
       'traverse_subpath': [],
       'user': <PropertiedUser 'admin'>}
  Module Products.PageTemplates.ZRPythonExpr, line 49, in __call__
   - __traceback_info__: date_components_support_view.result(inputvalue, 0, starting_year, ending_year, future_years)
  Module PythonExpr, line 1, in <expression>
  Module plone.app.form.widgets.datecomponents, line 50, in result
AttributeError: 'str' object has no attribute 'dates'

Change History

comment:1 Changed 6 years ago by kleist

Thanks for reporting this.

Could you please describe when this happens? When you click the "Save" button?

Does it happen every time you save a page?

Have you installed any add-on products?

comment:2 Changed 6 years ago by kleist

  • Status changed from new to closed
  • Resolution set to invalid

Reporter told us on #plone "After installing plone4 on the box,with ubuntu, everything works. I think it must be something with the python installation"

comment:3 follow-up: ↓ 4 Changed 4 years ago by sureshvv

  • Status changed from closed to reopened
  • Version set to 4.1
  • Resolution invalid deleted

Seeing this on 4.1.4 Unified Installer. Seems portal_state.locale() returns a string.

comment:4 in reply to: ↑ 3 Changed 4 years ago by pabo

Replying to sureshvv:

Seeing this on 4.1.4 Unified Installer. Seems portal_state.locale() returns a string.

Observing the same with 4.1.3 on Ubuntu 10.04.4 LTS, python '2.6.7 (r267:88850, Feb 3 2012, 01:02:07) \n[GCC 4.4.3]'. Yesterday it worked. But tonight the provider has updated some "core components". I have recompiled python and reinstalled plone but it does not help.

comment:5 Changed 4 years ago by sureshvv

No add-ons. 4.1.4 Unified Installer from scratch.

Wrote a one line Python script in custom

return context.REQUEST.locale

On a good install got <zope.i18n.locales.Locale object at 0xd54f6ac>

On a bad install got 'en-US'

Seems locale gets defined somewhere automatically.

Someone help.

Last edited 4 years ago by sureshvv (previous) (diff)

comment:6 follow-up: ↓ 7 Changed 4 years ago by sureshvv

I was able to fix this by patching ZPublisher.HTTPRequest as follows:

from ZPublisher.HTTPRequest import HTTPRequest, _marker

def __getattr__(self, key, default=_marker, returnTaints=0):
    if key == 'locale':
        # we only create the _locale on first access, as setting it
        # up might be slow and we don't want to slow down every
        # request
        if self._locale is _marker:
            self.setupLocale()
        return self._locale
    v = self.get(key, default, returnTaints=returnTaints)
    if v is _marker:
        if key == 'debug':
            return self._debug
        raise AttributeError, key
    return v

HTTPRequest.__getattr__ = __getattr__
Last edited 4 years ago by sureshvv (previous) (diff)

comment:7 in reply to: ↑ 6 Changed 4 years ago by pabo

Thank you, very useful patch.

comment:8 Changed 4 years ago by kleist

  • Keywords patch, upstream added
  • Status changed from reopened to confirmed
  • Component changed from Unknown to General
  • Milestone changed from 4.0 to 4.x

comment:9 Changed 4 years ago by kleist

  • Status changed from confirmed to closed
  • Resolution set to wontfix

comment:10 Changed 4 years ago by kleist

  • Status changed from closed to reopened
  • Resolution wontfix deleted

Or maybe we should monkeypatch Plone?

comment:11 Changed 4 years ago by kleist

  • Keywords patch, removed
  • Status changed from reopened to confirmed

Quoting Hanno on Launchpad:

The patch changes behavior in a backwards incompatible way.

In Zope 2 you can have a normal value in the request (or request.form) by the key 'locale'. If you have such a key, the special locale object won't be accessible. We can change this behavior in a new major version like Zope 4 and give the special locale object precedence over normal values. But we cannot do that in a maintenance release.

comment:12 Changed 3 years ago by silvio

I don't know exactly how to reproduce this, but it just bit me. I used this code to patch Plone, instead of patching Zope:

from plone.app.layout.globals.portal import PortalState

def locale(self):
    if not self.request._locale:
        self.request.setupLocale()
    return self.request._locale

PortalState.locale = locale

I leave it here as my 2¢.

comment:13 Changed 3 years ago by silvio

The error is related to the browser configuration: I currently see it with Crome, but everything works fine with Firefox.

A request that should trigger it is (given you have a user admin:secret):

GET /plone/portal_factory/Folder/folder.2013-04-11.6235490931/edit HTTP/1.1
Host: 127.0.0.1:55001
Connection: close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,it-IT;q=0.6,it;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: locale=en; tree-s="eJzTyCkw5NLIKTDiClZ3hANXW3WuAmOuxEQ9AIOOB9Q"; __ac="84O9r5ClghL29ipV%2BWILMR4Cgggoyvpg/S%2Bm7oTLXQo1MTY2NWYyM2FkbWluIQ%3D%3D"

If you save it in a file named /tmp/myrequest.txt you'll be able to run it with:

nc localhost 55001 < /tmp/myrequest.txt
Note: See TracTickets for help on using tickets.