gapic-generator-python
gapic-generator-python copied to clipboard
Don't send routing headers if resource prefixes are included in metadata
Environment details
- OS type and version: Ubuntu 20.04
- Python version: 3.7.13
- pip version: 22.04
gapic-generatorversion: N/A (bug in already generated libraries)
Steps to reproduce
- Install
pip install google-python-firebase==2.4.0(as a quick way of getting a generated client) - Create a generated
FirestoreAsyncClient - Try to send a "listen" request with
metadatausing agoogle-cloud-resource-prefixas required by the API
metadata = ( 'google-cloud-resource-prefix', database_string)
stream = await grpc_client.listen(requests=request_stream(database_string),
metadata=(metadata,))
...
- Get the following error:
google.api_core.exceptions.InvalidArgument: 400 Mismatch between database name in the request and http header ('google-cloud-resource-prefix' or 'x-goog-request-params') or query param 'database'
Note that this error occurs non-deterministically, likely because the headers are processed in a random order. 5. Monkey patch the resource prefix in place of the routing header (since the routing header function is assumed to always return):
metadata = ( 'google-cloud-resource-prefix', database_string)
with mock.patch('google.api_core.gapic_v1.routing_header.to_grpc_metadata', return_value=metadata):
stream = await grpc_client.listen(requests=request_stream(database_string),
# metadata=(metadata,)
)
....
- Observe problem is fixed.