Skip to content

Services incorrectly encode None arguments. #144

Closed

Description

@GoogleCodeExporter
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,, 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

Activity

  1. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    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

    • Changed state: Invalid
  2. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    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,, q=['car'])
      print req.uri
      req = service.translations().list(source='None',, 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

  3. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    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

  4. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    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

  5. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    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

    • Changed state: Accepted
  6. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    CL out for review: http://codereview.appspot.com/6306085/
    

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

  7. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    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

    • Changed state: Fixed
  8. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    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

    • Changed state: Started
  9. GoogleCodeExporter commented on Mar 28, 2016

    @GoogleCodeExporter
    Author
    This issue was closed by revision 97e37f2a20c1.
    

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

    • Changed state: Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions