internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: googleapis/google-cloud-python

Issue:
Rename main storage/datastore/etc. docs since captions now have the name
We end up just repeating the names. See http://googlecloudplatform.github.io/gcloud-python/latest/

![screen_shot_019](https://cloud.githubusercontent.com/assets/520669/9090839/750bac50-3b51-11e5-9244-b687c9f2fe00.png)

and http://gcloud-python.readthedocs.org/en/latest/

![screen_shot_018](https://cloud.githubusercontent.com/assets/520669/9090843/7aa950e0-3b51-11e5-86a5-a2a8f2ccfd68.png)

And notice that "Datastore" is both the heading name and the name of the first document in the heading.



Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -82,7 +82,7 @@
 
 # List of patterns, relative to source directory, that match files and
 # directories to ignore when looking for source files.
-exclude_patterns = ['_build', '_components/*']
+exclude_patterns = ['_build']
 
 # The reST default role (used for this markup: `text`) to use for all documents.
 #default_role = None


Test patch:
Repository: googleapis/google-cloud-python

Issue:
Don't completely fail when failing to parse an error
See #1438



Discussion:

Resolving patch:
diff --git a/gcloud/exceptions.py b/gcloud/exceptions.py
--- a/gcloud/exceptions.py
+++ b/gcloud/exceptions.py
@@ -181,9 +181,14 @@ def make_exception(response, content, error_info=None, use_json=True):
         content = content.decode('utf-8')
 
     if isinstance(content, six.string_types):
+        payload = None
         if use_json:
-            payload = json.loads(content)
-        else:
+            try:
+                payload = json.loads(content)
+            except ValueError:
+                # Expected JSON but received something else.
+                pass
+        if payload is None:
             payload = {'error': {'message': content}}
     else:
         payload = content


Test patch:
diff --git a/gcloud/test_exceptions.py b/gcloud/test_exceptions.py
--- a/gcloud/test_exceptions.py
+++ b/gcloud/test_exceptions.py
@@ -48,9 +48,10 @@ def test_ctor_explicit(self):
 
 class Test_make_exception(unittest2.TestCase):
 
-    def _callFUT(self, response, content):
+    def _callFUT(self, response, content, error_info=None, use_json=True):
         from gcloud.exceptions import make_exception
-        return make_exception(response, content)
+        return make_exception(response, content, error_info=error_info,
+                              use_json=use_json)
 
     def test_hit_w_content_as_str(self):
         from gcloud.exceptions import NotFound
@@ -77,6 +78,15 @@ def test_miss_w_content_as_dict(self):
         self.assertEqual(exception.message, 'Unknown Error')
         self.assertEqual(list(exception.errors), [ERROR])
 
+    def test_html_when_json_expected(self):
+        from gcloud.exceptions import NotFound
+        response = _Response(NotFound.code)
+        content = '<html><body>404 Not Found</body></html>'
+        exception = self._callFUT(response, content, use_json=True)
+        self.assertTrue(isinstance(exception, NotFound))
+        self.assertEqual(exception.message, content)
+        self.assertEqual(list(exception.errors), [])
+
 
 class _Response(object):
     def __init__(self, status):
Repository: googleapis/google-cloud-python

Issue:
'QueryResults.job' returns a new instance on each access.
See second item of #1551.



Discussion:

Resolving patch:
diff --git a/gcloud/bigquery/query.py b/gcloud/bigquery/query.py
--- a/gcloud/bigquery/query.py
+++ b/gcloud/bigquery/query.py
@@ -50,6 +50,7 @@ def __init__(self, query, client):
         self._properties = {}
         self.query = query
         self._configuration = _SyncQueryConfiguration()
+        self._job = None
 
     @property
     def project(self):
@@ -134,9 +135,12 @@ def job(self):
         :returns: Job instance used to run the query (None until
                   ``jobReference`` property is set by the server).
         """
-        job_ref = self._properties.get('jobReference')
-        if job_ref is not None:
-            return QueryJob(job_ref['jobId'], self.query, self._client)
+        if self._job is None:
+            job_ref = self._properties.get('jobReference')
+            if job_ref is not None:
+                self._job = QueryJob(job_ref['jobId'], self.query,
+                                     self._client)
+        return self._job
 
     @property
     def page_token(self):


Test patch:
diff --git a/gcloud/bigquery/test_query.py b/gcloud/bigquery/test_query.py
--- a/gcloud/bigquery/test_query.py
+++ b/gcloud/bigquery/test_query.py
@@ -156,6 +156,8 @@ def test_job_w_jobid(self):
         self.assertEqual(job.query, self.QUERY)
         self.assertTrue(job._client is client)
         self.assertEqual(job.name, SERVER_GENERATED)
+        fetched_later = query.job
+        self.assertTrue(fetched_later is job)
 
     def test_schema(self):
         client = _Client(self.PROJECT)
Repository: googleapis/google-cloud-python

Issue:
[Documentation Issue] 
Page Name: pubsub-subscription
Release: 0.12.0

The reference link for modify_ack_deadline points to the acknowledge method.
"See: https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/acknowledge"



Discussion:
Thanks @ronniemaor 


Resolving patch:
diff --git a/gcloud/pubsub/subscription.py b/gcloud/pubsub/subscription.py
--- a/gcloud/pubsub/subscription.py
+++ b/gcloud/pubsub/subscription.py
@@ -234,7 +234,7 @@ def modify_ack_deadline(self, ack_id, ack_deadline, client=None):
         """API call:  update acknowledgement deadline for a retrieved message.
 
         See:
-        https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/acknowledge
+        https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/modifyAckDeadline
 
         :type ack_id: string
         :param ack_id: ack ID of message being updated


Test patch:
Repository: googleapis/google-cloud-python

Issue:
Restore testing of grpc under py27
Once grpc 0.13.1 releases with a fix for https://github.com/grpc/grpc/issues/5280.

See: https://github.com/grpc/grpc/pull/5319#issuecomment-192412023



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@
     'pyOpenSSL',
     'six',
 ]
-GRPC_EXTRAS = ['grpcio >= 0.13.0']
+GRPC_EXTRAS = ['grpcio >= 0.13.1']
 
 setup(
     name='gcloud',


Test patch:
Repository: googleapis/google-cloud-python

Issue:
dns.zone.ManagedZone does not update dns_name during reload
When calling `ManagedZone.reload`, the zone's `dns_name` is not updated from the returned response.



Discussion:

Resolving patch:
diff --git a/gcloud/dns/zone.py b/gcloud/dns/zone.py
--- a/gcloud/dns/zone.py
+++ b/gcloud/dns/zone.py
@@ -219,6 +219,7 @@ def _set_properties(self, api_response):
         """
         self._properties.clear()
         cleaned = api_response.copy()
+        self.dns_name = cleaned.pop('dnsName', None)
         if 'creationTime' in cleaned:
             cleaned['creationTime'] = _rfc3339_to_datetime(
                 cleaned['creationTime'])


Test patch:
diff --git a/gcloud/dns/test_zone.py b/gcloud/dns/test_zone.py
--- a/gcloud/dns/test_zone.py
+++ b/gcloud/dns/test_zone.py
@@ -349,10 +349,12 @@ def test_reload_w_bound_client(self):
         RESOURCE = self._makeResource()
         conn = _Connection(RESOURCE)
         client = _Client(project=self.PROJECT, connection=conn)
-        zone = self._makeOne(self.ZONE_NAME, self.DNS_NAME, client)
+        zone = self._makeOne(self.ZONE_NAME, client=client)
 
         zone.reload()
 
+        self.assertEqual(zone.dns_name, self.DNS_NAME)
+
         self.assertEqual(len(conn._requested), 1)
         req = conn._requested[0]
         self.assertEqual(req['method'], 'GET')
Repository: googleapis/google-cloud-python

Issue:
GAX API hangs during (second) 'publish'
/cc @bjwatson 

``` python
======================================================================
ERROR: test_message_pull_mode_e2e (pubsub.TestPubsub)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/system_tests/pubsub.py", line 157, in test_message_pull_mode_e2e
    topic.publish(MESSAGE_1, extra=EXTRA_1)
  File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/gcloud/pubsub/topic.py", line 246, in publish
    message_ids = api.topic_publish(self.full_name, [message_data])
  File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/gcloud/pubsub/_gax.py", line 171, in topic_publish
    event.wait()
AttributeError: 'exceptions.AttributeError' object has no attribute 'message_ids'
```



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,7 @@
 
 setup(
     name='gcloud',
-    version='0.15.0',
+    version='0.16.0',
     description='API Client library for Google Cloud',
     author='Google Cloud Platform',
     author_email='jjg+gcloud-python@google.com',


Test patch:
Repository: googleapis/google-cloud-python

Issue:
Read the Docs build failing
https://readthedocs.org/projects/gcloud-python/builds/4108022/
https://readthedocs.org/projects/gcloud-python/builds/4108027/



Discussion:
https://readthedocs.org/projects/gcloud-python/builds/4105578/
https://readthedocs.org/projects/gcloud-python/builds/4105025/

@tseaver these all look like GRPCIO 0.14.0 issues.

Is this something from https://github.com/GoogleCloudPlatform/gcloud-python/issues/1814?

Yes, the dependency for the pubsub and logging APIs is now on GRPCIO 0.14.0. Looks like the build server needs it installed.

Thanks @bjwatson! I think appveyor needs to clear its cache as well possibly? I haven't used appveyor before though.

@bjwatson The RTD build failures show a huge bunch of compilation warnings trying to build `grpcio 0.14.0`:

``` C
In file included from ./include/grpc/support/alloc.h:37:0,
                 from ./src/python/grpcio/grpc/_cython/imports.generated.h:869,
                 from ./src/python/grpcio/grpc/_cython/loader.h:37,
                 from ./src/python/grpcio/grpc/_cython/cygrpc.c:310:
./include/grpc/impl/codegen/alloc.h:68:1: warning: function declaration isn't a prototype [-Wstrict-prototypes]
 GPRAPI gpr_allocation_functions gpr_get_allocation_functions();
 ^
...
third_party/zlib/gzwrite.c: In function 'gzclose_w':
third_party/zlib/gzwrite.c:573:5: warning: implicit declaration of function 'close' [-Wimplicit-function-declaration]
     if (close(state->fd) == -1)
     ^
```

followed by:

``` python
zip_safe flag not set; analyzing archive contents...
No eggs found in /tmp/easy_install-JdusyT/grpcio-0.14.0/egg-dist-tmp-TNTJot (setup script problem?)
error: The 'grpcio>=0.14.0' distribution was not found and is required by gcloud
```

Any clues to the source of the error?

You could just fake the dep like [`oauth2client` does](https://github.com/google/oauth2client/blob/c82816cf7a8a4a3b587b3690937069d502e609f3/docs/conf.py#L13-L15). This is a recommended practice.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,7 @@
     'gax-google-pubsub-v1',
 ]
 
-if sys.version_info[:2] == (2, 7):
+if sys.version_info[:2] == (2, 7) and 'READTHEDOCS' not in os.environ:
     REQUIREMENTS.extend(GRPC_EXTRAS)
 
 setup(


Test patch:
Repository: googleapis/google-cloud-python

Issue:
Pub/Sub empty topic batch fails
``` python
with topic.batch() as batch:
  for obj in rows:
    batch.publish(b'bla')
```

fails if rows is empty:

Traceback (most recent call last):
…
File "/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/topic.py", line 420, in **exit**
self.commit()
File "/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/topic.py", line 449, in commit
message_ids = api.topic_publish(self.topic.full_name, self.messages[:])
File "/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/connection.py", line 205, in topic_publish
method='POST', path='/%s:publish' % (topic_path,), data=data)
File "/usr/local/lib/python2.7/dist-packages/gcloud/connection.py", line 344, in api_request
error_info=method + ' ' + url)
BadRequest: 400 The value for message_count is too small. You passed 0 in the request, but the minimum value is 1. (POST https://pubsub.googleapis.com/v1/projects/karos-api/topics/api-prod:publish)



Discussion:
Thanks for the report!  `gcloud.pubsub.topic.Batch.commit` should indeed be a no-op if there are no messages accumulated.


Resolving patch:
diff --git a/gcloud/pubsub/topic.py b/gcloud/pubsub/topic.py
--- a/gcloud/pubsub/topic.py
+++ b/gcloud/pubsub/topic.py
@@ -443,6 +443,9 @@ def commit(self, client=None):
         :param client: the client to use.  If not passed, falls back to the
                        ``client`` stored on the current batch.
         """
+        if not self.messages:
+            return
+
         if client is None:
             client = self.client
         api = client.publisher_api


Test patch:
diff --git a/gcloud/pubsub/test_topic.py b/gcloud/pubsub/test_topic.py
--- a/gcloud/pubsub/test_topic.py
+++ b/gcloud/pubsub/test_topic.py
@@ -228,6 +228,18 @@ def test_publish_multiple_w_bound_client(self):
         self.assertEqual(api._topic_published,
                          (self.TOPIC_PATH, [MESSAGE1, MESSAGE2]))
 
+    def test_publish_w_no_messages(self):
+        client = _Client(project=self.PROJECT)
+        api = client.publisher_api = _FauxPublisherAPI()
+        api._topic_publish_response = []
+        topic = self._makeOne(self.TOPIC_NAME, client=client)
+
+        with topic.batch() as batch:
+            pass
+
+        self.assertEqual(list(batch.messages), [])
+        self.assertEqual(api._api_called, 0)
+
     def test_publish_multiple_w_alternate_client(self):
         import base64
         PAYLOAD1 = b'This is the first message text'
@@ -716,6 +728,7 @@ def test_context_mgr_failure(self):
 
 
 class _FauxPublisherAPI(object):
+    _api_called = 0
 
     def topic_create(self, topic_path):
         self._topic_created = topic_path
@@ -735,6 +748,7 @@ def topic_delete(self, topic_path):
 
     def topic_publish(self, topic_path, messages):
         self._topic_published = topic_path, messages
+        self._api_called += 1
         return self._topic_publish_response
 
     def topic_list_subscriptions(self, topic_path, page_size=None,
Repository: googleapis/google-cloud-python

Issue:
pep8 is dead
As of version 1.7.0, [`pep8`](https://pypi.python.org/pypi/pep8) is no longer getting releases, the tool is now called [`pycodestyle`](https://pypi.python.org/pypi/pycodestyle/). Visit https://github.com/PyCQA/pep8 to see the redirect.

This means we haven't had any updates since January 12, 2016. Oops.



Discussion:

Resolving patch:
diff --git a/scripts/pep8_on_repo.py b/scripts/pycodestyle_on_repo.py
similarity index 76%
rename from scripts/pep8_on_repo.py
rename to scripts/pycodestyle_on_repo.py
--- a/scripts/pep8_on_repo.py
+++ b/scripts/pycodestyle_on_repo.py
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-"""Custom script to run pep8 on gcloud codebase.
+"""Custom script to run pycodestyle on gcloud codebase.
 
-This runs pep8 as a script via subprocess but only runs it on the
+This runs pycodestyle as a script via subprocess but only runs it on the
 .py files that are checked in to the repository.
 """
 
@@ -25,15 +25,15 @@
 
 
 def main():
-    """Run pep8 on all Python files in the repository."""
+    """Run pycodestyle on all Python files in the repository."""
     git_root = subprocess.check_output(
         ['git', 'rev-parse', '--show-toplevel']).strip()
     os.chdir(git_root)
     python_files = subprocess.check_output(['git', 'ls-files', '*py'])
     python_files = python_files.strip().split()
 
-    pep8_command = ['pep8'] + python_files
-    status_code = subprocess.call(pep8_command)
+    pycodestyle_command = ['pycodestyle'] + python_files
+    status_code = subprocess.call(pycodestyle_command)
     sys.exit(status_code)
 
 


Test patch:
Repository: googleapis/google-cloud-python

Issue:
Docu broken
If i try to click on "Source Code" link @ https://googlecloudplatform.github.io/gcloud-python/#/docs/master/gcloud/datastore/client/client?method=gcloud.datastore.client.Client.put_multi
i get a 404.

404: Link: https://github.com/GoogleCloudPlatform/gcloud-python/blob/master/.tox/json-docs/lib/python2.7/site-packages/gcloud/datastore/client.py#L331



Discussion:
Thanks for the report @xamoom-raphael!

This seems to be related to #2022 and https://github.com/GoogleCloudPlatform/gcloud-common/issues/154.

However that last one looks like the link didn't generate correctly.


Resolving patch:
diff --git a/scripts/generate_json_docs.py b/scripts/generate_json_docs.py
--- a/scripts/generate_json_docs.py
+++ b/scripts/generate_json_docs.py
@@ -24,6 +24,11 @@
 
 from verify_included_modules import get_public_modules
 
+import gcloud
+
+ABSOLUTE_LIBRARY_PATH = os.path.dirname(os.path.dirname(os.path.abspath(
+    gcloud.__file__)))
+
 
 class Module(object):
 
@@ -290,10 +295,10 @@ def build_type(type_id, title, contents):
 
 def clean_source_path(source):
     source_path = ''
-    if 'gcloud-python' in source:
-        source_path = source.split('gcloud-python')[1]
+    if ABSOLUTE_LIBRARY_PATH in source:
+        source_path = source.replace(ABSOLUTE_LIBRARY_PATH, source)
 
-    return source_path[1:]
+    return source_path
 
 
 def process_code_blocks(doc):
@@ -552,6 +557,7 @@ def main():
             'credentials': [],
             'datastore': [],
             'dns': [],
+            'error_reporting': [],
             'environment_vars': [],
             'exceptions': [],
             'iterator': [],


Test patch:
Repository: googleapis/google-cloud-python

Issue:
Why do we have Angular vendor deps checked in?



Discussion:
e.g. https://github.com/GoogleCloudPlatform/gcloud-python/blob/master/docs/json/src/vendor-7173ada14e.js

The gcloud-common doc site runs on angular.
This is the standard way that you deploy the doc site AFAIK.

Alternatives would be to pull the link in from a CDN but then you would have to track which versions are being updated and used by gcloud-common/site each time you deploy.

This file should contain all vendor related JS so that there is less HTTP connection overhead. i.e. one JS file to download instead of however many libs you use.

Not sure if that's the answer you were looking for or not?

Why doesn't it get pulled in with `gcloud-common`?

Right now the files are getting staged in doc/json. Which makes it easy for testing (`python -m SimpleHTTPServer`).

We could make it more automated and have the deploy script pull in `gcloud-common` and do a `gulp build` then copy the files over. But we would have to setup all the dependencies for that in travis.

These could live in the `gh-pages` branch permanently. That's what the other projects do.
I just don't feel like `gh-pages` is very permanent so I build everything from the main repo, package it up and then deploy it to `gh-pages`.

I am out of my element here, do what you think is right, just don't want our hardcoded files to drift from the ones in `gcloud-common`

These are generated from `gulp build` in gcloud-common so I'm not too worried.
The process to update them is to do the `gulp build` and then copy over the `dist/src` folder that's generated.

The ideal solution IMHO, would be have travis do a new build of gcloud-common/site with each doc deploy and gcloud-common/site had changed since the last deploy of gcloud-python's docs. Not sure how to track that though.

You just need to write a script to check out `gcloud-common` on Travis and `gulp build`. You can utilize Travis caching to make this more efficient if you like.

That way you don't have to worry about drift and we don't have files in our repo which aren't part of the build.

Having to update them on a regular basis seems a bad idea.


Resolving patch:
diff --git a/scripts/generate_json_docs.py b/scripts/generate_json_docs.py
--- a/scripts/generate_json_docs.py
+++ b/scripts/generate_json_docs.py
@@ -580,11 +580,9 @@ def package_files(generated_json_dir, docs_build_dir, static_json_dir,
             - master/
                 - toc.json
                 - types.json
-                - home.html
                 - index.json
                 - overview.html
             - home.html
-        - home.html
         - index.html
         - manifest.json
     """


Test patch:
Repository: googleapis/google-cloud-python

Issue:
Bigtable instance undelete doesn't exist
The documentation and some code comments think there should be an undelete for bigtable instances:

https://github.com/GoogleCloudPlatform/gcloud-python/blob/e63b1d8bd24a826c28865a21766ee7537ce87285/gcloud/bigtable/instance.py#L283

https://googlecloudplatform.github.io/gcloud-python/stable/bigtable-instance.html

but AFAICT looking at code it appears to be unimplemented.



Discussion:
Thanks for the report!  `UndeleteCluster` endpoint went away in [V2 of the API](https://cloud.google.com/bigtable/docs/reference/admin/rpc/google.bigtable.admin.v2#google.bigtable.admin.v2.BigtableInstanceAdmin).  The `Instance` concept is new in V2, and never had an `UndeleteInstance` endpoint.

The artifacts you are seeing are fossils (in the `Cluster` docstrings) and copy-past of fossils (in the `Instance` docstrings).


Resolving patch:
diff --git a/gcloud/bigtable/cluster.py b/gcloud/bigtable/cluster.py
--- a/gcloud/bigtable/cluster.py
+++ b/gcloud/bigtable/cluster.py
@@ -67,7 +67,6 @@ class Cluster(object):
     * :meth:`create` itself
     * :meth:`update` itself
     * :meth:`delete` itself
-    * :meth:`undelete` itself
 
     .. note::
 
@@ -267,11 +266,6 @@ def delete(self):
 
         * All tables within the cluster will become unavailable.
 
-        Prior to the cluster's ``delete_time``:
-
-        * The cluster can be recovered with a call to ``UndeleteCluster``.
-        * All other attempts to modify or delete the cluster will be rejected.
-
         At the cluster's ``delete_time``:
 
         * The cluster and **all of its tables** will immediately and
diff --git a/gcloud/bigtable/instance.py b/gcloud/bigtable/instance.py
--- a/gcloud/bigtable/instance.py
+++ b/gcloud/bigtable/instance.py
@@ -76,7 +76,6 @@ class Instance(object):
     * :meth:`create` itself
     * :meth:`update` itself
     * :meth:`delete` itself
-    * :meth:`undelete` itself
 
     .. note::
 
@@ -278,11 +277,6 @@ def delete(self):
 
         * All tables within the instance will become unavailable.
 
-        Prior to the instance's ``delete_time``:
-
-        * The instance can be recovered with a call to ``UndeleteInstance``.
-        * All other attempts to modify or delete the instance will be rejected.
-
         At the instance's ``delete_time``:
 
         * The instance and **all of its tables** will immediately and


Test patch: