Use of unrestrictedTraverse

Guys,
I need to know the exact use of unrestrictedTraverse().From the docs what I understood is ,
It will check for the permissions on a content for the particular user and return all the objects irrespective of the roles.

I have used it in the following code,

	    portal_catalog=api.portal.get_tool('portal_catalog')
		stories=portal_catalog(path="/".join(self.context.getPhysicalPath()),portal_type='story')
		self.context.plone_log(stories)
		for brain in stories:
			i+=1
			story=self.context.unrestrictedTraverse(brain.getObject())
			self.context.plone_log(story.worked_hrs)
			yield({
				'id':'sub_progress',
				'url':brain.getURL(),
				'comment':story.title,
				'name':story.owners,
				'owners':story.owners,
				'date':story.date,
				'worked_hrs':story.worked_hrs,	
			})

story=self.context.unrestrictedTraverse(brain.getObject())

but I am recieving the following error:

Traceback (innermost last):

Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module plone.autoform.view, line 47, in __call__
Module plone.autoform.view, line 38, in render
Module Products.Five.browser.pagetemplatefile, line 125, in __call__
Module Products.Five.browser.pagetemplatefile, line 59, in __call__
Module zope.pagetemplate.pagetemplate, line 132, in pt_render
Module five.pt.engine, line 93, in __call__
Module z3c.pt.pagetemplate, line 163, in render
Module chameleon.zpt.template, line 261, in render
Module chameleon.template, line 171, in render
Module 70a35f81e7106c84b455932399dfa9ad.py, line 590, in render
Module daf1c743ecceb868b86eead62aa0eaaa.py, line 1223, in render_master
Module daf1c743ecceb868b86eead62aa0eaaa.py, line 420, in render_content
Module 70a35f81e7106c84b455932399dfa9ad.py, line 279, in __fill_content_core
Module chameleon.tal, line 471, in __call__
Module plonexp.leocorn.browser.story, line 17, in storyList
Module OFS.Traversable, line 165, in unrestrictedTraverse
IndexError: list index out of range

I need the list of stories irrespective of the user roles and access.

Kindly help me

Read the documentation instead of guessing API calls.

https://docs.plone.org/develop/plone/serving/traversing.html#traversing-by-full-path

clearly tells you that you need to pass in a path and not a content object.

story=self.context.unrestrictedTraverse(brain.getObject())

makes zero sense. Traversing is about paths...so why pass a full object here?

Obviously you only need the object that is related to the brain which is what brain.getObject() is already doing. So why do you want to traverse into something? And in particular keep your fingers away from unrestrictedTraverse() - you usually never needs that API unless you know what you are doing (which is not the case here).

Can you stop being rude?

Relax and chill

There is little point in saying it again as you've had it pointed out many a time.

but

At my estimate I would say that for every 2 people you help with your quick and helpful responses you probably chase away another 1 person who didn't expect to spoken to in what most people would interpret as a rude manner. Chase away as in ditch the technology, community and are never seen from again.
On balance it would be better to answer nothing at all for that 1 in 3 case IMO than write something that could be interpreted as insulting and aggressive (no matter how much you feel it's the truth). That would at least give time for someone with manners to answer with the same information and make everyones day a little lighter. If someone new seems stupid to you, just don't respond. Please.

Again, I take the freedom to express my feelings if someone is notoriously ignorant, arrogant and death on recommendations and answers.

no one is denying you have that freedom.
Just pointing out it hurts the community for which you currently invest time and energy in and I'm guessing the health of said community might impact your income at some point. So seems kind of an ignorant and arrogant thing to be doing IMO.

1 Like