[Zope] "Bad Request" error on calling a zsql method

Jean Lagarde jlagarde@bigfoot.com
Wed, 06 Jun 2001 20:41:24 -0700


Good day,

I've been using Zope and Python for about two weeks now, and I've been 
able to figure everything for myself so far (with the help of this list 
and other docs, of course). I've figured how to work around the 
following problem,  but I don't understand what causes the error in the 
first place. I have not been able to find an instance of the error type 
"Bad request" in this group or searching zope.org.

The problem comes up when trying to call a zsql method with implicit 
argument passing. The zsql method (insertOccurences) declares the two 
arguments 'occurence' and 'problemID'. The calling dtml is as follows:

<dtml-let 
problemID="radarDBSessionData.getSessionData().get('insertedProblemID')">
 <dtml-in occurences>
  <dtml-let occurence=sequence-item>
    <dtml-call insertOccurence>
  </dtml-let>
 </dtml-in occurences>
</dtml-let>

On running this, Zope returns the following error:

Error Type: Bad Request
Error Value: ['occurence', 'problemID']

Traceback (innermost last):
 File D:\pf2\radar\lib\python\ZPublisher\Publish.py, line 223, in 
publish_module
 File D:\pf2\radar\lib\python\ZPublisher\Publish.py, line 187, in publish
 File D:\pf2\radar\lib\python\Zope\__init__.py, line 221, in 
zpublisher_exception_hook
  (Object: Traversable)
 File D:\pf2\radar\lib\python\ZPublisher\Publish.py, line 171, in publish
 File D:\pf2\radar\lib\python\ZPublisher\mapply.py, line 160, in mapply
  (Object: selectProblemPage)
 File D:\pf2\radar\lib\python\ZPublisher\Publish.py, line 112, in 
call_object
  (Object: selectProblemPage)
 File D:\pf2\radar\lib\python\OFS\DTMLMethod.py, line 189, in __call__
  (Object: selectProblemPage)
 File D:\pf2\radar\lib\python\DocumentTemplate\DT_String.py, line 538, 
in __call__
  (Object: selectProblemPage)
 File D:\pf2\radar\lib\python\DocumentTemplate\DT_Let.py, line 147, in 
render
  (Object: 
problemID="radarDBSessionData.getSessionData().get('insertedProblemID')")
 File D:\pf2\radar\lib\python\DocumentTemplate\DT_In.py, line 717, in 
renderwob
  (Object: occurences)
 File D:\pf2\radar\lib\python\DocumentTemplate\DT_Let.py, line 147, in 
render
  (Object: occurence=sequence-item)
 File D:\pf2\radar\lib\python\Shared\DC\ZRDB\DA.py, line 476, in __call__
  (Object: insertOccurence)
 File D:\pf2\radar\lib\python\Shared\DC\ZRDB\Aqueduct.py, line 150, in 
_argdata
  (Object: insertOccurence)
Bad Request: (see above)

My workaround is to pass the arguments explicitely, i.e.

<dtml-call 
"insertOccurence(occurence=_.getitem('occurence'),problemID=_.getitem('problemID'))"> 


But I think that this should be unnecessary. Anybody has an explanation 
for the error? I admit that I may still have some fundamental 
misunderstanding of the Zope namespace and of method calling (for 
example, why is it  necessary to include _=_ in the arguments list to 
get the namespace in a script, even  after declaring the binding?), so 
maybe the reason will be obvious to some of you  Python/Zope Gods.

Bonus question: The 'occurences' (plural) variable above was produced by 
using the :records type qualifier on a form (great feature by the way). 
I have not been able to figure the type of the returned object, and I am 
curious. If I iterate over the list, the sequence-item has the keys() 
method, but trying to set a key in a script (x['thekey']=y) produces the 
error ("object does not support item assigment"). Similarly, I can use 
getattr on the object, but setattr returns the error ('attribute-less 
object'). Is this due to the security limitations of Zope's own 
implementation of setitem and setattr? Any description of these 
limitations available somewhere? I suppose I can always try to find out 
from the appropriate .py file, but given my inexperience with Python, I 
don't have the time for that right now. If the issue is security, then 
is the  only way to "fix up" (e.g. reformat a date string) items in a 
form record or  records to do it in an external method?

Cheers,

Jean