kulpa / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

Services incorrectly encode None arguments. #144

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Download the example app, samples/translate/main.py.
2. Edit the request such that the optional argument source=None
  service.translations().list(source=None, target='fr', q=['car']).execute()

What is the expected output? What do you see instead?
Printing the request URI reveals that None is encoded as the string "None" as 
opposed to excluding the relevant argument.

What version of the product are you using? On what operating system?
2.0beta8

Please provide any additional information below.

Original issue reported on code.google.com by yova...@google.com on 11 Jun 2012 at 10:21

GoogleCodeExporter commented 9 years ago
Do not include parameters you want excluded. Supplying a parameter with a value 
of None as a value has a very different meaning than not supplying the 
parameter at all. 

Original comment by jcgregorio@google.com on 12 Jun 2012 at 1:10

GoogleCodeExporter commented 9 years ago
The concern more generally is that there is no distinction between the string 
"None" and the null value None.

Adding this:

  req = service.translations().list(source=None, target='fr', q=['car'])
  print req.uri
  req = service.translations().list(source='None', target='fr', q=['car'])
  print req.uri

to the translations example yields the identical strings:

  https://www.googleapis.com/language/translate/v2?q=car&source=None&alt=json&target=fr&key=AIzaSyBGbYmf-u_tY_gnQCzIEicOnxVL03vf9Ow
  https://www.googleapis.com/language/translate/v2?q=car&source=None&alt=json&target=fr&key=AIzaSyBGbYmf-u_tY_gnQCzIEicOnxVL03vf9Ow

I haven't tested a patch() operation, but I suspect this indistinguishability 
will be particularly problematic there.

Original comment by yova...@google.com on 12 Jun 2012 at 2:13

GoogleCodeExporter commented 9 years ago
The library knows that the 'source' parameter in this case is supposed to be a 
string and casts what you pass in as a string, thus you get 'None'. If it 
happened to be an int it would raise an exception, since you can't cast a None 
to int, so I could see adding code to raise an exception in the case of string 
parameters to keep the behavior consistent.

Patch only applies to bodies of the request, and during a patch JSON 
serialization will convert a None to null.

Original comment by jcgregorio@google.com on 12 Jun 2012 at 2:22

GoogleCodeExporter commented 9 years ago
Thanks for clarifying this.

An exception might be useful, but might also set a precedent for other special 
cases.

Original comment by yova...@google.com on 12 Jun 2012 at 2:38

GoogleCodeExporter commented 9 years ago
Re-opening to track adding the exception in the case of passing in None for a 
string parameter.

Original comment by jcgregorio@google.com on 12 Jun 2012 at 2:59

GoogleCodeExporter commented 9 years ago
CL out for review: http://codereview.appspot.com/6306085/

Original comment by jcgregorio@google.com on 14 Jun 2012 at 7:57

GoogleCodeExporter commented 9 years ago
Fixed in 
http://code.google.com/p/google-api-python-client/source/detail?r=e283dfe361a674
2f621f4699a81c23d78a3bcc12

Original comment by jcgregorio@google.com on 14 Jun 2012 at 8:19

GoogleCodeExporter commented 9 years ago
Based on feedback changing the behavior so that None means to ignore the 
parameter.

CL out for review: http://codereview.appspot.com/6295108/

Original comment by jcgregorio@google.com on 20 Jun 2012 at 4:00

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 97e37f2a20c1.

Original comment by jcgregorio@google.com on 20 Jun 2012 at 4:22