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

Issue:
Client library should not try to validate sample rate
The client library should allow validation of sample rate to occur on the server rather than trying to do it's own validation.  Allowing the server to check errors means that we don't need to update the client if the server expands the range of sample rates that it supports.

[https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/speech/google/cloud/speech/sample.py#L70][1]

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/speech/google/cloud/speech/sample.py#L70


Discussion:

Resolving patch:
diff --git a/speech/google/cloud/speech/sample.py b/speech/google/cloud/speech/sample.py
--- a/speech/google/cloud/speech/sample.py
+++ b/speech/google/cloud/speech/sample.py
@@ -66,11 +66,6 @@ def __init__(self, content=None, source_uri=None, stream=None,
         self._content = content
         self._source_uri = source_uri
         self._stream = stream
-
-        if (sample_rate_hertz is not None and
-                not 8000 <= sample_rate_hertz <= 48000):
-            raise ValueError('The value of sample_rate_hertz must be between '
-                             '8000 and 48000.')
         self._sample_rate_hertz = sample_rate_hertz
 
         if encoding is not None and getattr(Encoding, encoding, False):


Test patch:
diff --git a/speech/tests/unit/test_sample.py b/speech/tests/unit/test_sample.py
--- a/speech/tests/unit/test_sample.py
+++ b/speech/tests/unit/test_sample.py
@@ -84,13 +84,6 @@ def test_bytes_converts_to_file_like_object(self):
     def test_sample_rates(self):
         from google.cloud.speech.encoding import Encoding
 
-        with self.assertRaises(ValueError):
-            self._make_one(
-                source_uri=self.AUDIO_SOURCE_URI, sample_rate_hertz=7999)
-        with self.assertRaises(ValueError):
-            self._make_one(
-                source_uri=self.AUDIO_SOURCE_URI, sample_rate_hertz=48001)
-
         sample = self._make_one(
             encoding=Encoding.FLAC,
             sample_rate_hertz=self.SAMPLE_RATE,
Repository: googleapis/google-cloud-python

Issue:
Client library incorrectly returns error when FLAC is used with long-running-recognize
The client library incorrectly returns an error when anything other than LINEAR16 is used for a long-running recognize request:

[https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/speech/google/cloud/speech/sample.py#L173][1]

The v1 server support all encodings so this breaks functionality.

In general, the client library should almost never do it's own validation; it should always delegate to the server to be sure that that behavior and error messages are consistent across APIs.

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/46e417e838001f4d1eb13f5e3fc2a54d390dd5db/speech/google/cloud/speech/sample.py#L173


Discussion:
> In general, the client library should almost never do it's own validation; it should always delegate to the server to be sure that that behavior and error messages are consistent across APIs.

I am +(a million) on this.

Resolving patch:
diff --git a/speech/google/cloud/speech/sample.py b/speech/google/cloud/speech/sample.py
--- a/speech/google/cloud/speech/sample.py
+++ b/speech/google/cloud/speech/sample.py
@@ -170,9 +170,6 @@ def long_running_recognize(self, language_code, max_alternatives=None,
         :rtype: :class:`~google.cloud.speech.operation.Operation`
         :returns: Operation for asynchronous request to Google Speech API.
         """
-        if self.encoding is not Encoding.LINEAR16:
-            raise ValueError('Only LINEAR16 encoding is supported by '
-                             'long-running speech requests.')
         api = self._client.speech_api
         return api.long_running_recognize(
             self, language_code, max_alternatives, profanity_filter,


Test patch:
diff --git a/speech/tests/unit/test_sample.py b/speech/tests/unit/test_sample.py
--- a/speech/tests/unit/test_sample.py
+++ b/speech/tests/unit/test_sample.py
@@ -119,14 +119,3 @@ def test_encoding(self):
             source_uri=self.AUDIO_SOURCE_URI,
         )
         self.assertEqual(sample.encoding, Encoding.FLAC)
-
-    def test_async_linear16_only(self):
-        from google.cloud.speech.encoding import Encoding
-
-        sample = self._make_one(
-            encoding=Encoding.FLAC,
-            sample_rate_hertz=self.SAMPLE_RATE,
-            source_uri=self.AUDIO_SOURCE_URI,
-        )
-        with self.assertRaises(ValueError):
-            sample.long_running_recognize(language_code='en-US')
Repository: googleapis/google-cloud-python

Issue:
encoding.py missing OGG_OPUS and SPEEX_WITH_HEADER_BYTE encodings
The new encodings  OGG_OPUS and SPEEX_WITH_HEADER_BYTE are missing.

[https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/speech/google/cloud/speech/encoding.py][1]

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/46e417e838001f4d1eb13f5e3fc2a54d390dd5db/speech/google/cloud/speech/encoding.py


Discussion:
@lukesneeringer Are these in some `pb2` module?

Resolving patch:
diff --git a/speech/google/cloud/speech/encoding.py b/speech/google/cloud/speech/encoding.py
--- a/speech/google/cloud/speech/encoding.py
+++ b/speech/google/cloud/speech/encoding.py
@@ -36,3 +36,9 @@ class Encoding(object):
 
     AMR_WB = 'AMR_WB'
     """AMR_WB encoding type."""
+
+    OGG_OPUS = 'OGG_OPUS'
+    """OGG_OPUS encoding type."""
+
+    SPEEX_WITH_HEADER_BYTE = 'SPEEX_WITH_HEADER_BYTE'
+    """SPEEX_WITH_HEADER_BYTE encoding type."""


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

Issue:
IAM policy should return an empty set of the bindings do not exist
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/bd9fdfba07fac63a91847628613928a569250c0f/core/google/cloud/iam.py#L71

Should return an empty set if no bindings are set for that role.


Discussion:
Current behavior leads to `KeyError`, yes?
ya, I'd like to be able to do:

```python
policy = something.get_iam_policy()
policy['roles/editor'].add('whatever')
something.set_iam_policy(policy)
```

and it'll work regardless of if any editors had been previously set.
@jonparrott ISTM like you want a `collections.defaultdict(set)`?

In #3325 a similar snippet was **failing** because `policy.owners` returned a `frozenset`. In the `__getitem__` case, the raw binding will be returned, which we [guarantee][1] is a `set`. Is it a bad thing that the two different means of access produce different behavior?

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/bd9fdfba07fac63a91847628613928a569250c0f/core/google/cloud/iam.py#L73-L74
Defaultdict is pretty much what I'm after, in terms of behavior.
I'm fine with the old/deprecated methods returning a frozenset.

Resolving patch:
diff --git a/core/google/cloud/iam.py b/core/google/cloud/iam.py
--- a/core/google/cloud/iam.py
+++ b/core/google/cloud/iam.py
@@ -59,7 +59,7 @@ class Policy(collections.MutableMapping):
     def __init__(self, etag=None, version=None):
         self.etag = etag
         self.version = version
-        self._bindings = {}
+        self._bindings = collections.defaultdict(set)
 
     def __iter__(self):
         return iter(self._bindings)


Test patch:
diff --git a/core/tests/unit/test_iam.py b/core/tests/unit/test_iam.py
--- a/core/tests/unit/test_iam.py
+++ b/core/tests/unit/test_iam.py
@@ -52,8 +52,7 @@ def test_ctor_explicit(self):
 
     def test___getitem___miss(self):
         policy = self._make_one()
-        with self.assertRaises(KeyError):
-            policy['nonesuch']
+        self.assertEqual(policy['nonesuch'], set())
 
     def test___setitem__(self):
         USER = 'user:phred@example.com'
Repository: googleapis/google-cloud-python

Issue:
Chaining ACL grants on Storage does not work.
So from what I can tell [this](https://github.com/GoogleCloudPlatform/google-cloud-python/blob/ce6756fbe3633c74fd742567654565147628f4ba/storage/google/cloud/storage/acl.py#L56) doesn't work.

Example:
```python
acl.all().grant_read().revoke_write()
```

None of the grant methods return an object to chain to.
See:  https://github.com/GoogleCloudPlatform/google-cloud-python/blob/486163e5378897961bc3cf367062c8b10cf7ce3e/storage/google/cloud/storage/acl.py#L148-L170

Should I just take this out of the docs?




Discussion:
I would rather fix the code to match the docs.
~SGTM, I'll get a PR together.~ Ha I see you have.
Those docs may be leftovers from some early development:  we've mostly avoided the `return self` chaining thing on purpose.
Based on feedback to #3183, please change the docs. :-)
👍 
Has this been done?

Resolving patch:
diff --git a/storage/google/cloud/storage/acl.py b/storage/google/cloud/storage/acl.py
--- a/storage/google/cloud/storage/acl.py
+++ b/storage/google/cloud/storage/acl.py
@@ -53,13 +53,6 @@
    :start-after: [START acl_user_settings]
    :end-before: [END acl_user_settings]
 
-You can also chain these ``grant_*`` and ``revoke_*`` methods together
-for brevity:
-
-.. literalinclude:: storage_snippets.py
-   :start-after: [START acl_revoke_write]
-   :end-before: [END acl_revoke_write]
-
 After that, you can save any changes you make with the
 :func:`google.cloud.storage.acl.ACL.save` method:
 


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

Issue:
Broken link
Hello,

I found that the link at [https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/core/google/cloud/client.py#L33][1] is broken.

https://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/661816540f1387bcc6e08b0fd722f4abae585b37/core/google/cloud/client.py#L33


Discussion:
Potential replacement candidate: http://google-auth.readthedocs.io/en/latest/
Thanks for filing @parthea!

This is the new location: https://google-cloud-python.readthedocs.io/en/latest/core/auth.html

Would you like to send a PR to get credit for your find? It will be super easy, no unit tests needed :grinning: 

Resolving patch:
diff --git a/core/google/cloud/client.py b/core/google/cloud/client.py
--- a/core/google/cloud/client.py
+++ b/core/google/cloud/client.py
@@ -29,8 +29,8 @@
 
 _GOOGLE_AUTH_CREDENTIALS_HELP = (
     'This library only supports credentials from google-auth-library-python. '
-    'See https://google-cloud-python.readthedocs.io/en/latest/'
-    'google-cloud-auth.html for help on authentication with this library.'
+    'See https://google-cloud-python.readthedocs.io/en/latest/core/auth.html '
+    'for help on authentication with this library.'
 )
 
 


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

Issue:
Docstrings from fetch_data method needs to be updated
Hello,

Recently a [question](https://stackoverflow.com/questions/44895829/bigquery-async-query-job-the-fetch-results-method-returns-wrong-number-of-va) was posted in SO asking about the return params of the `fetch_data` method of `QueryResults' in BigQuery client.

As it seems, the return is no longer a tuple with 3 values but rather an object of the class `HTTPIterator`. Looks like the docstrings needs to be updated (if it could describe some quick example of how to use the iterator it'd be quite helpful :)!)

Thanks,



Discussion:
Hi @WillFuks,
Thank you for reporting this. We will get that updated.

Resolving patch:
diff --git a/bigquery/google/cloud/bigquery/query.py b/bigquery/google/cloud/bigquery/query.py
--- a/bigquery/google/cloud/bigquery/query.py
+++ b/bigquery/google/cloud/bigquery/query.py
@@ -414,13 +414,12 @@ def fetch_data(self, max_results=None, page_token=None, start_index=None,
         :param client: the client to use.  If not passed, falls back to the
                        ``client`` stored on the current dataset.
 
-        :rtype: tuple
-        :returns: ``(row_data, total_rows, page_token)``, where ``row_data``
-                  is a list of tuples, one per result row, containing only
-                  the values;  ``total_rows`` is a count of the total number
-                  of rows in the table;  and ``page_token`` is an opaque
-                  string which can be used to fetch the next batch of rows
-                  (``None`` if no further batches can be fetched).
+        :rtype: :class:`~google.cloud.iterator.Iterator`
+        :returns: Iterator of row data :class:`tuple`s. During each page, the
+                  iterator will have the ``total_rows`` attribute set,
+                  which counts the total number of rows **in the result
+                  set** (this is distinct from the total number of rows in
+                  the current page: ``iterator.page.num_items``).
         :raises: ValueError if the query has not yet been executed.
         """
         if self.name is None:


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

Issue:
Is MergeFrom used by accident (instead of CopyFrom) in bigtable.Table.create?
See [source][1]. As an example of why `MergeFrom` instead of `CopyFrom` can be a bug:

```python
>>> from google.protobuf.timestamp_pb2 import Timestamp
>>> from google.cloud.bigtable._generated.bigtable_instance_admin_pb2 import (
...     CreateInstanceMetadata)
>>>
>>> metadata1 = CreateInstanceMetadata(request_time=Timestamp(nanos=100))
>>> metadata2 = CreateInstanceMetadata(request_time=Timestamp(nanos=100))
>>> t = Timestamp(seconds=1000)
>>> metadata1
request_time {
  nanos: 100
}

>>> metadata2
request_time {
  nanos: 100
}

>>> t
seconds: 1000

>>>
>>> metadata1.request_time.MergeFrom(t)
>>> metadata2.request_time.CopyFrom(t)
>>>
>>> metadata1
request_time {
  seconds: 1000
  nanos: 100
}

>>> metadata2
request_time {
  seconds: 1000
}
```

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/2d81f88454724f0a672b453c994413c3cf1110c7/bigtable/google/cloud/bigtable/table.py#L184


Discussion:
@tseaver I assigned to you but a `git blame` reveals I am the last one to touch that line.
In that particular case, the target starts as an empty `Table` protobuf.  Unless the `column_families` argument contains entries with duplicate `column_family_id` values, there won't be any effective difference between `CopyFrom` and `MergeFrom`.
In other words, we aren't **relying** on `MergeFrom`, but (assuming users don't pass in duplicate names with different settings) the code "works fine"?

In that case, ISTM that we should

- Switch from `CopyFrom` (since it will be the same in the "safe case" and is it what we intend)
- Add a guard that a key can't be written over

WDYT?

Resolving patch:
diff --git a/bigtable/google/cloud/bigtable/table.py b/bigtable/google/cloud/bigtable/table.py
--- a/bigtable/google/cloud/bigtable/table.py
+++ b/bigtable/google/cloud/bigtable/table.py
@@ -181,7 +181,7 @@ def create(self, initial_split_keys=None, column_families=()):
             table_pb = table_v2_pb2.Table()
             for col_fam in column_families:
                 curr_id = col_fam.column_family_id
-                table_pb.column_families[curr_id].MergeFrom(col_fam.to_pb())
+                table_pb.column_families[curr_id].CopyFrom(col_fam.to_pb())
 
         request_pb = table_admin_messages_v2_pb2.CreateTableRequest(
             initial_splits=initial_split_keys or [],


Test patch:
diff --git a/bigtable/tests/unit/test_table.py b/bigtable/tests/unit/test_table.py
--- a/bigtable/tests/unit/test_table.py
+++ b/bigtable/tests/unit/test_table.py
@@ -255,7 +255,7 @@ def _create_test_helper(self, initial_split_keys, column_families=()):
             for cf in column_families:
                 cf_pb = table_pb.column_families[cf.column_family_id]
                 if cf.gc_rule is not None:
-                    cf_pb.gc_rule.MergeFrom(cf.gc_rule.to_pb())
+                    cf_pb.gc_rule.CopyFrom(cf.gc_rule.to_pb())
         request_pb = _CreateTableRequestPB(
             initial_splits=splits_pb,
             parent=self.INSTANCE_NAME,
Repository: googleapis/google-cloud-python

Issue:
Fix broken references to old auth doc
See #3517 and https://github.com/GoogleCloudPlatform/google-cloud-python/commit/7cb86b47acea2339c6c18cb70189d2b0c347ec5e#commitcomment-22758235


Discussion:
Also #3578
#3610 / #3611 / #3630 also reveal we might have some other renames to track down.

Resolving patch:
diff --git a/core/google/cloud/credentials.py b/core/google/cloud/credentials.py
--- a/core/google/cloud/credentials.py
+++ b/core/google/cloud/credentials.py
@@ -60,7 +60,7 @@ def _get_signed_query_params(credentials, expiration, string_to_sign):
               signed payload.
     """
     if not isinstance(credentials, google.auth.credentials.Signing):
-        auth_uri = ('http://google-cloud-python.readthedocs.io/en/latest/'
+        auth_uri = ('https://google-cloud-python.readthedocs.io/en/latest/'
                     'core/auth.html?highlight=authentication#setting-up-'
                     'a-service-account')
         raise AttributeError('you need a private key to sign credentials.'
diff --git a/storage/google/cloud/storage/bucket.py b/storage/google/cloud/storage/bucket.py
--- a/storage/google/cloud/storage/bucket.py
+++ b/storage/google/cloud/storage/bucket.py
@@ -1015,7 +1015,7 @@ def generate_upload_policy(
         credentials = client._base_connection.credentials
 
         if not isinstance(credentials, google.auth.credentials.Signing):
-            auth_uri = ('http://google-cloud-python.readthedocs.io/en/latest/'
+            auth_uri = ('https://google-cloud-python.readthedocs.io/en/latest/'
                         'core/auth.html?highlight=authentication#setting-up-'
                         'a-service-account')
             raise AttributeError(


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

Issue:
Bigtable Cluster.create() does not send location
[Only][1] `serve_nodes` is used in the payload:

```python
    return messages_v2_pb2.CreateClusterRequest(
        parent=cluster._instance.name,
        cluster_id=cluster.cluster_id,
        cluster=data_v2_pb2.Cluster(
            serve_nodes=cluster.serve_nodes,
        ),
    )
```

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/08021bd85df19d073b33412dbd4ff4dbc8be008d/bigtable/google/cloud/bigtable/cluster.py#L51-L54


Discussion:

Resolving patch:
diff --git a/bigtable/google/cloud/bigtable/cluster.py b/bigtable/google/cloud/bigtable/cluster.py
--- a/bigtable/google/cloud/bigtable/cluster.py
+++ b/bigtable/google/cloud/bigtable/cluster.py
@@ -49,6 +49,7 @@ def _prepare_create_request(cluster):
         parent=cluster._instance.name,
         cluster_id=cluster.cluster_id,
         cluster=data_v2_pb2.Cluster(
+            location=cluster.location,
             serve_nodes=cluster.serve_nodes,
         ),
     )


Test patch:
diff --git a/bigtable/tests/unit/test_cluster.py b/bigtable/tests/unit/test_cluster.py
--- a/bigtable/tests/unit/test_cluster.py
+++ b/bigtable/tests/unit/test_cluster.py
@@ -393,12 +393,14 @@ def test_it(self):
         instance = _Instance(INSTANCE_ID, client)
         cluster = Cluster(CLUSTER_ID, instance,
                           serve_nodes=SERVE_NODES)
+        cluster.location = u'projects/prahj-ekt/locations/zona-tres'
 
         request_pb = self._call_fut(cluster)
 
         self.assertEqual(request_pb.cluster_id, CLUSTER_ID)
         self.assertEqual(request_pb.parent, instance.name)
         self.assertEqual(request_pb.cluster.serve_nodes, SERVE_NODES)
+        self.assertEqual(request_pb.cluster.location, cluster.location)
 
 
 def _ClusterPB(*args, **kw):
Repository: googleapis/google-cloud-python

Issue:
Document Storage.Blob setter for metadata
Hi! 

Based on other methods that have a getter and setter for example [bucket.cors](https://googlecloudplatform.github.io/google-cloud-python/stable/storage/buckets.html#google.cloud.storage.bucket.Bucket.cors).

I have a request to document the metadata setter found [here](https://github.com/GoogleCloudPlatform/google-cloud-python/blob/ffd7cca2c1bbcf71b753913eab4d95ec0ca04f8a/storage/google/cloud/storage/blob.py#L1408) to documentation found [here]( https://googlecloudplatform.github.io/google-cloud-python/stable/storage/blobs.html#google.cloud.storage.blob.Blob.metadata). 

Thank you!


Discussion:

Resolving patch:
diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py
--- a/storage/google/cloud/storage/blob.py
+++ b/storage/google/cloud/storage/blob.py
@@ -1399,6 +1399,11 @@ def metadata(self):
 
         See https://cloud.google.com/storage/docs/json_api/v1/objects
 
+        :setter: Update arbitrary/application specific metadata for the
+                 object.
+        :getter: Retrieve arbitrary/application specific metadata for
+                 the object.
+
         :rtype: dict or ``NoneType``
         :returns: The metadata associated with the blob or ``None`` if the
                   property is not set locally.


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

Issue:
Increment threadsafety on BigQuery DB-API interface when httplib2 is removed
From https://github.com/GoogleCloudPlatform/google-cloud-python/pull/2921/files/5b29a9e42a40f7c74ced0b7a7e9db0add52a20a1#r123596828

Blocked by https://github.com/GoogleCloudPlatform/google-cloud-python/issues/1998


Discussion:
I would love to finish the work for #1998!

It's right now blocked on BigQuery's usage of `google.cloud.streaming`, which I've actually **finished** ripping out in https://github.com/dhermes/google-cloud-python/tree/bigquery-remove-streaming. Alas, the unit tests will be a hard days slog!
@tswast this is now possible since #1998 has been resolved.
Yay! (If only GitHub had a "blocked by" feature with nice notifications.)

Resolving patch:
diff --git a/bigquery/google/cloud/bigquery/dbapi/__init__.py b/bigquery/google/cloud/bigquery/dbapi/__init__.py
--- a/bigquery/google/cloud/bigquery/dbapi/__init__.py
+++ b/bigquery/google/cloud/bigquery/dbapi/__init__.py
@@ -55,8 +55,8 @@
 
 apilevel = '2.0'
 
-# Threads may share the module, but not connections.
-threadsafety = 1
+# Threads may share the module and connections, but not cursors.
+threadsafety = 2
 
 paramstyle = 'pyformat'
 


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

Issue:
Explicitly depend on setuptools
Context: #3295

We should explicitly depend on a minimum version of setuptools to get around problems installing our packages if setuptools is too old.


Discussion:
This is just like a CYA? Isn't this kind of the chicken or the egg, like `setup.py` doesn't work because of an old version of `setuptools`, so we are going to require a newer version in `setup.py`?
I've hit this problem in the past few days - google-cloud-* modules can't be installed on clean Python environments installed using PyEnv, so had to use pip to upgrade setuptools first. Seems reasonable that you add a include the requirement so you can be installed seamlessly: it's not an obvious error, and quite hard to find this issue to find the answer.
@ndenny I've had the same issue with "fresh-ish" `pyenv` environments, thanks for pointing this out.

Resolving patch:
diff --git a/core/setup.py b/core/setup.py
--- a/core/setup.py
+++ b/core/setup.py
@@ -55,6 +55,7 @@
     'protobuf >= 3.0.0',
     'google-auth >= 0.4.0, < 2.0.0dev',
     'requests >= 2.4.0, < 3.0.0dev',
+    'setuptools >= 34.0.0',
     'six',
     'tenacity >= 4.0.0, <5.0.0dev'
 ]


Test patch: