gapic-generator-python icon indicating copy to clipboard operation
gapic-generator-python copied to clipboard

Don't send routing headers if resource prefixes are included in metadata

Open elibixby opened this issue 3 years ago • 0 comments

Environment details

  • OS type and version: Ubuntu 20.04
  • Python version: 3.7.13
  • pip version: 22.04
  • gapic-generator version: N/A (bug in already generated libraries)

Steps to reproduce

  1. Install pip install google-python-firebase==2.4.0 (as a quick way of getting a generated client)
  2. Create a generated FirestoreAsyncClient
  3. Try to send a "listen" request with metadata using a google-cloud-resource-prefix as required by the API
metadata = ( 'google-cloud-resource-prefix', database_string)
stream = await grpc_client.listen(requests=request_stream(database_string),
                                                    metadata=(metadata,))
...
  1. 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,)

    )
    ....
  1. Observe problem is fixed.

elibixby avatar Jun 06 '22 15:06 elibixby