Open mbookman opened 3 years ago
Hi @mbookman. Thanks for suggesting an improvement! Are you interested in creating a pull request?
I'd be happy to. Any guidance on:
client_options
field to use (re-use api_endpoint
or add something new)?Resource()
constructor signature (or for example re-use the baseUrl
)Thanks,
-Matt
@mbookman Thanks for filing this issue! I would expect setting api_endpoint
to change the endpoint for batch requests as well.
I'd prefer option 2 (using self._baseUrl
instead of rootDesc["rootUrl"]
when constructing the batch path) in Resource
.
I'm going to relabel this issue as a feature request since the OP mentioned that there is a currently a solution available to set the _batch_uri
manually which works without modifications to the source. For example, using the code below:
from googleapiclient.discovery import build
lifesciences = build('lifesciences', 'v2beta')
ls_batch = lifesciences.new_batch_http_request(callback=_no_op)
ls_batch._batch_uri = 'https://us-west2-lifesciences.googleapis.com/batch'
print(ls_batch._batch_uri)
Pull requests are welcome!
When creating a service the
discovery.build()
function calls in to create a newResource()
. The Resource adds a thenew_batch_http_request()
function here:https://github.com/googleapis/google-api-python-client/blob/c6912836e88eea45aef7d515383e549082d37717/googleapiclient/discovery.py#L1342
In that block of code, the batch URI is set based on fixed values from the service description:
for other endpoints, the URI can be overridden with client_options
https://github.com/googleapis/google-api-python-client/blob/c6912836e88eea45aef7d515383e549082d37717/googleapiclient/discovery.py#L493
This is important for the Google Lifesciences API, which supports regional batch endpoints. So when sending batch requests for operations in the
us-west2
region, for example, we need to be able to target:I've worked around this for the time being by creating my own
new_batch_http_request()
function that allows for a custom batch_uri, but it would be nice for the Python client here to support aclient_options
field for this.