unrestrictedTraverse() relies on REQUEST

Bug #680403 reported by Mikko Ohtamaa
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Low
Unassigned

Bug Description

unrestrictedTraverse() relies on the presence of acquired HTTP REQUEST object and does not gracefully handle situation when unrestrictedTraverse() is called outside HTTP request lifecycle. If you call getObject() for a catalog brain which does not exist from a command line script, the following exception is produced.

Sample traceback:

  import ZPublisher, Zope
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "src/collective.mountpoint/collective/mountpoint/bin/update.py", line 31, in ?
    sys.exit(main(app))
  File "/srv/plone/saariselka/src/collective.mountpoint/collective/mountpoint/updateclient.py", line 243, in main
    exit_code = updater.updateAll()
  File "/srv/plone/saariselka/src/collective.mountpoint/collective/mountpoint/updateclient.py", line 151, in updateAll
    mountpoints = list(self.getMountPoints())
  File "/srv/plone/saariselka/src/collective.mountpoint/collective/mountpoint/updateclient.py", line 49, in getMountPoints
    return [ brain.getObject() for brain in brains ]
  File "/srv/plone/saariselka/parts/zope2/lib/python/Products/ZCatalog/CatalogBrains.py", line 86, in getObject
    target = parent.restrictedTraverse(path[-1])
  File "/srv/plone/saariselka/parts/zope2/lib/python/OFS/Traversable.py", line 301, in restrictedTraverse
    return self.unrestrictedTraverse(path, default, restricted=True)
  File "/srv/plone/saariselka/parts/zope2/lib/python/OFS/Traversable.py", line 259, in unrestrictedTraverse
    next = queryMultiAdapter((obj, self.REQUEST),
AttributeError: REQUEST

This is a corner case inside exception handler, but it should still be able to work without REQUEST.

Revision history for this message
Kevin Teague (kevin-bud) wrote :

You can also bump into this bug when running the upgrade profile for PloneHelpCenter (Plone 4.0.2 with Zope 2.12.13).

Changed in zope2:
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Gil (gforcada) wrote :

Any idea or workaround on how to solve this kind of problem? I'm stuck with an async job that just throws this error when it tries to get an object from its uuid (via plone.app.uuid).

Revision history for this message
Colin Watson (cjwatson) wrote :

The zope2 project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope2.

Changed in zope2:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.