[Zope-CMF] Problem after invokeFactory

Chris Withers chris at simplistix.co.uk
Wed Feb 2 05:25:45 EST 2005

Rob Boyd wrote:
> # From foo_add_control.py
> try:
>   context.invokeFactory('Foo', id, context.REQUEST.RESPONSE)
>   # It no longer gets to here, but it used to!

You'r passing the response object, maybe a redirect is being raised as a 
result? try NOT passing the response object and see what happens...

>   # Tested with: raise "Just added a new foo" but no exception raised

it wouldn't, 'cos you swallow it further down, d'oh!

> except:
>   return context.setStatus(False, 'Could not add Foo %s' % id )

why why why do people feel the need to wrap things in global 
try/excepts?! All this does is mask errors that you want to know about, 
and might even cause ZODB corruption if you're really unlucky...
(google for try except and conflict error)

> # Foo's factory method
> def addGroup(self, id, title = '', REQUEST = {}):
>   """
>   Factory method for a Foo object
>   """
>   foo = Foo(id, title)
>   self._setObject(id, foo)
>   # make sure that creator has special role to begin with  
>   foo = getattr(self, id)
>   membership = getToolByName(self, 'portal_membership')
>   member = membership.getAuthenticatedMember()
>   foo.manage_setLocalRoles(member.getUserName(), ['FooRole',])
>   if REQUEST.has_key('RESPONSE'):
>     return REQUEST.RESPONSE.redirect('manage_main')

bingo, there's your redirect. When did that get added?


Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk

More information about the Zope-CMF mailing list