[ZCM] [ZC] 322/ 3 Assign "Z SQL method can not use parameter name with "client""

Collector: Zope Bugs, Features, and Patches ... zope-coders@zope.org
Mon, 16 Dec 2002 15:57:03 -0500


Issue #322 Update (Assign) "Z SQL method can not use parameter name with "client""
 Status Accepted, Zope/bug+solution medium
To followup, visit:
  http://collector.zope.org/Zope/322

==============================================================
= Assign - Entry #3 by rdmurray on Dec 16, 2002 3:57 pm

 Status: Pending => Accepted

 Supporters added: rdmurray

We can at least improve the error message so the user knows
how to fix the problem.

________________________________________
= Comment - Entry #2 by ajung on Mar 29, 2002 12:06 pm

I fear that renaming 'client' to something else might break 
some existing code that call the object with 'client' as keyword argument. 

-aj
________________________________________
= Request - Entry #1 by Anonymous User on Mar 29, 2002 5:12 am

when I write a Z SQL method using an argument named "client", it always report error "Error, exceptions.TypeError: __call__() got multiple values for keyword argument 'client' "

Thanks Dieter Maurer, he points out that its due to the __call__ definition

 def __call__(client=None, REQUEST=None, **kw)

thus when **kw contain my argument "client", there is a conflict.

I do suggest changing the client parameter to __client__, as it's really frequent used. Or at least we add it to the Zope Book that "client" is reserved.

Thanks

Ren Bing

The following is attached mail from Dieter Maurer.


Ren Bing writes:
 > But the point is the name is "client" but not "id", I know "id" should be
 > avoid of, but who expects "client"? And the most important is that, there's
 > nowhere mentioned "client", and supposely explicitly specified argument or
 > variable should override other thing except reserved keyword of python
 > language, is that right? OK, I checked python documentation, "client" is not
 > a reserved keyword.

The following happens in your case:

  The DTML object's "__call__" is defined by

      def __call__(client=None, REQUEST=None, **kw)

  The ZSQL method wants to call it with itself as client
  (to allow the DTML object to use acquisition) and the provided
  arguments as keywords.
  It probably calls it with something like:

     apply(self.source,(self,),kw)

  and Python raises the exception you saw, because "client" got
  two values.

"client" is mentioned many times -- in the context of DTML objects.
And the body of a Z SQL method is a DTML object.
I do not blame you that you did not recognize this. It is very natural.

On the other hand, it is really difficult to document and catch all
such potential issues.

The best possible solution would be that Z SQL methods would check
for such name clashes and provide a meaningful error message.

Please file a bug report to <http://collector.zope.org>.


Dieter

==============================================================