Repository: googleapis/google-cloud-python

Issue:
Error passing 'fields' to pubsub GET API for subscription
```
$ tox -e regression --notest
GLOB sdist-make: /home/tseaver/projects/agendaless/Google/src/gcloud-python/setup.py
regression inst-nodeps: /home/tseaver/projects/agendaless/Google/src/gcloud-python/.tox/dist/gcloud-0.4.3.zip
___________________________________ summary ____________________________________
  regression: skipped tests
  congratulations :)
$ .tox/regression/bin/python regression/run_regression.py --package=pubsub
test_create_subscription (pubsub.TestPubsub) ... ERROR
test_create_topic (pubsub.TestPubsub) ... ok
test_list_subscriptions (pubsub.TestPubsub) ... ok
test_list_topics (pubsub.TestPubsub) ... ok
test_message_pull_mode_e2e (pubsub.TestPubsub) ... ERROR

ERROR: test_create_subscription (pubsub.TestPubsub)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/regression/pubsub.py", line 74, in test_create_subscription
    self.assertFalse(subscription.exists())
  File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/.tox/regression/lib/python2.7/site-packages/gcloud/pubsub/subscription.py", line 112, in exists
    query_params={'fields': 'name'})
  File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/.tox/regression/lib/python2.7/site-packages/gcloud/connection.py", line 293, in api_request
    raise make_exception(response, content)
gcloud.exceptions.BadRequest: 400 Invalid JSON payload received. Unknown name "fields": Cannot bind query parameter.
```

I omitted a similar failure in another test:  both are for a call to `subscription.exists()` where the expected value is False.

@dhermes this is the one I was working around in #794 

@jgeewax maybe tag w/ "google bug"?



Discussion:
Whoa! @tmatsuo note that `fields` is in the [discovery doc](https://www.googleapis.com/discovery/v1/apis/pubsub/v1beta2/rest), but does not actually work when used.

@tseaver Shall we "fix" be re-implementing your previous commit? (PS Good thing exception handling is finally working the way we want :))

Caused breakage in regression tests on master:

  https://travis-ci.org/GoogleCloudPlatform/gcloud-python/builds/57382647

Interestingly, the second failure I saw does not appear there.  #heisenbug

It would be nice to have confirmation that `fields` is not expected to be passed for non-existing subscriptions.  @tmatsuo can you comment?


Resolving patch:
diff --git a/gcloud/pubsub/subscription.py b/gcloud/pubsub/subscription.py
--- a/gcloud/pubsub/subscription.py
+++ b/gcloud/pubsub/subscription.py
@@ -74,9 +74,7 @@ def exists(self):
         """
         conn = self.topic.connection
         try:
-            conn.api_request(method='GET',
-                             path=self.path,
-                             query_params={'fields': 'name'})
+            conn.api_request(method='GET', path=self.path)
         except NotFound:
             return False
         else:


Test patch:
diff --git a/gcloud/pubsub/test_subscription.py b/gcloud/pubsub/test_subscription.py
--- a/gcloud/pubsub/test_subscription.py
+++ b/gcloud/pubsub/test_subscription.py
@@ -95,7 +95,7 @@ def test_exists_miss(self):
         req = conn._requested[0]
         self.assertEqual(req['method'], 'GET')
         self.assertEqual(req['path'], '/%s' % SUB_PATH)
-        self.assertEqual(req['query_params'], {'fields': 'name'})
+        self.assertEqual(req.get('query_params'), None)
 
     def test_exists_hit(self):
         PROJECT = 'PROJECT'
@@ -111,7 +111,7 @@ def test_exists_hit(self):
         req = conn._requested[0]
         self.assertEqual(req['method'], 'GET')
         self.assertEqual(req['path'], '/%s' % SUB_PATH)
-        self.assertEqual(req['query_params'], {'fields': 'name'})
+        self.assertEqual(req.get('query_params'), None)
 
     def test_reload(self):
         PROJECT = 'PROJECT'