[Zope-dev] Help - Unexpected context behaviour?

Bernie Rossi Bernie.Rossi@senet.com.au
Fri, 22 Sep 2000 17:33:11 +0930


I am relatively new to Zope and Python and am trying to convert a Zope
'product' from
version 2.1.4 (working okay) to 2.2.2 (the latest) and I'm having the
following Zope Error when trying to publish the resource;

Error Type: AttributeError
Error Value: 'string' object has no attribute 'has_key'

The code in question appears below (with non-important stuff taken out);

Python code;

def getContext(self):
    # return the list of parents up to the project level in reverse order
    . . .

def getAbsoluteURL(self, REQUEST):
    """ Attempt to get the absolute URL of this object by building it
manually"""
    print "Self : ", self.title
    print "Request : ", REQUEST
    . . .
   if REQUEST.has_key( 'URL1' ) :
      str = REQUEST['URL1']
   . . .

DTML Code;

   <dtml-in "getContext()">
      <option value="<dtml-var
expr="getAbsoluteURL(REQUEST)">/manage_container"
      <dtml-if expr="currId==getId()">
       SELECTED
      </dtml-if>
      >
      . . .
      </option>
   </dtml-in>

The function getContext does infact return a list of object instances
(tested and okay) and also
therefore the related REQUEST (I've assumed?). So that when we loop through
the list (in the DTML), the 'context' of the 'current' object should change.
Thus we can interrogate each instance and do whatever we want (certainly in
previous versions of Zope).

But what in fact I'm getting is the following (unexpected) debug
information;

Self : 'Object Name'
Request : <Special Object Used to Force Acquisition>

(and the Zope error as mentioned above) with the error line number pointing
to the
' if REQUEST.has_key( 'URL1' ) :' statement.

If I hack the code to avoid the above test (for the first instance only) the
code works (?), in that the next item in the object list is processed
correctly (only two objects in the list).

So it appears that the REQUEST object (since it hasn't got a method
'has_key') is invalid for the parent object (which Zope thinks is a 'String'
object rather than a REQUEST?) but okay for the other.

I don't understand this behaviour, is this due to the changes in security
implemented in the latest
version or due to some other changes?

Any help or advice would be appreciated.

Regards
Bernie Rossi.