开发者

Viewing Plone custom content type yields AttributeError: 'NoneType' object has no attribute 'getPhysicalPath'

With a lot of help (I'm a v. inexperienced programmer/Plone developer) I've created some custom content types on a new Plone website. I'm now experiencing an error. The content type is called 'Organisation' and it has an optional multi-value reference field with an 'allowed type' of 'site' (another of my custom content types). I created a whole lot of organisation entries; all fine. I then linked some of them to sites. They saved OK but now, a week or two later, when I try to view any of these I get this error message:

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.Five.browser.metaconfigure, line 477, in __call__
Module Products.Five.browser.pagetemplatefile, line 126, in __call__
Module Products.Five.browser.pagetemplatefile, line 60, in __call__
Module zope.pagetemplate.pagetemplate, line 113, in pt_render
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 954, in do_defineSlot
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterp开发者_Go百科reter, 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 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 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 583, in do_setLocal_tal
Module zope.tales.tales, line 696, in evaluate
URL: file:/usr/local/Plone/buildout-cache/eggs/archetypes.referencebrowserwidget-2.1-py2.6.egg/archetypes/referencebrowserwidget/skins/referencebrowser/referencebrowser.pt
Line 57, Column 12
Expression: <PythonExpr '/'.join(obj.getPhysicalPath())>
Names:

{'args': (),
 'container': <Organisation at /ecn/what-we-do/about/sponsors/ccw>,
 'context': <Organisation at /ecn/what-we-do/about/sponsors/ccw>,
 'default': <object object at 0xb75f86d0>,
 'here': <Organisation at /ecn/what-we-do/about/sponsors/ccw>,
 'loop': {},
 'nothing': None,
 'options': {},
 'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0xcadb89c>,
 'request': <HTTPRequest, URL=http://la-ecnweb1.nerc-lancaster.ac.uk:8080/ecn/what-we-do/about/sponsors/ccw/organisation_view>,
 'root': <Application at >,
 'template': <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0xaa4154c>,
 'traverse_subpath': [],
 'user': <PropertiedUser 'admin'>,
 'view': <Products.Five.metaclass.SimpleViewClass from /usr/local/Plone/zinstance/src/ceh.ecn_theme/ceh/ecn_theme/browser/templates/organisation_view.pt object at 0xc926aec>,
 'views': <Products.Five.browser.pagetemplatefile.ViewMapper object at 0xc926aac>}

Module Products.PageTemplates.ZRPythonExpr, line 49, in __call__
__traceback_info__: '/'.join(obj.getPhysicalPath())
Module PythonExpr, line 1, in <expression>

AttributeError: 'NoneType' object has no attribute 'getPhysicalPath'

'Organisations' which don't make reference to a site display fine. Can anyone suggest what might be the problem? I wondered if it was an index problem so have tried updating portal_catalog, reference_catalog and uid_catalog but that hasn't helped.

Strangely, I've created a new 'Organisation' and linked it to a 'Site' and it works fine. Also, I tested all my custom types and templates on a local instance of Plone on my laptop and it all works fine there. It's as if something has corrupted these particular objects since they were first created.

  • The configuration is: Plone 4.0.3 Zope 2.12.14 Python 2.6.5 (r265:79063, Aug 13 2010, 14:26:16) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)]
  • The site is here: http://la-ecnweb1.nerc-lancaster.ac.uk:8080/ecn
  • One of the problem content types is: http://la-ecnweb1.nerc-lancaster.ac.uk:8080/ecn/what-we-do/about/sponsors/ccw

Please advise if you need me to post any code and I will do.

Thanks.


If you moved the organizations in some way that bypassed the machinery used to update references or if that machinery was somehow broken, then that would explain the troubles. I think clearing the reference_catalog and uid_catalog followed by a "Clear and Rebuild" of the portal_catalog will probably address your issue. You'll find that button below the "Update Catalog" toward the middle of that same page in the ZMI of the portal_catalog. The "Update Catalog" process assumes the catalog already correctly knows where all the objects to be indexed are, but that's exactly the problem here, one or more of the catalogs has not been kept up to date on where your "Site"s are. That's where "Clear and Rebuild" comes in. From the docs on that page in the ZMI:

Clear and Rebuild will remove all entries from the catalog, and then walk the entire portal looking for content objects which should be indexed in the catalog and index them. Doing this will remove inappropriate entries from the portal catalog (scripts, templates) and preserve all indexed content. This may take a long time, but it is the correct way to rebuild a catalog that has had objects improperly added or removed.

If that doesn't work, or if you're just curious, you'll have to find out which reference is causing the problem. Find an example "Organization" with the error, start the debugger with something like "bin/instance debug", then do something like:

>>> portal = app.unrestrictedTraverse('/portal_name')
>>> org = portal.unrestrictedTraverse('path/to/buggy/organization') # no leading slash
>>> broken = [item for item in org.getReferenceImpl(field_relationship) if item.getTargetObject() is None]
>>> brains = portal.uid_catalog.unrestrictedSearchResults(UID=[item.targetUID for item in broken])
>>> from pprint import pprint
>>> pprint([brain.getPath() for brain in brains])

That should print out a list of the paths which the catalog involved thinks the sites are at. You can inspect that and see more of what's going on. You can also poke more around what's in the "broken" and "brains" lists to see more of what's going on.


It seems like the referenced object is not there anymore. It cannot be looked up by UUID, so somewhere in the reference_catalog None is returned (_objectByUUID).

I think archetypes.referencebrowserwidget should handle this case, but it does not.

Do you remember which site you referenced? Is it still there? Are you able to somehow drop the reference and recreate it?

Cheers


Had similar problem: it seems something didn't work in "references system" when a referenced page was cancelled. The page was marked as Undisclosed

Overriding referencebrowser.pt changing line from 164 to 172 solves my problem

in archetypes/referencebrowserwidget/skins/referencebrowser/referencebrowser.pt

<label tal:define="title set/title_or_id | string:Undisclosed;
                   obj_path python: set and '/'.join(set.getPhysicalPath()) or None;">
   <input type="checkbox" 
          tal:attributes="name string:${fieldName}:list;
                          value python:helper.getUidFromReference(set);
                          checked python: set and 'checked' or None;
                          style python: not set and 'display:none' or None;" 
           checked="checked" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜