Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

from_grpc fails with got an unexpected keyword argument 'retry' #87

Closed

Description

@rodis

A call to from_grpc fails with

Traceback (most recent call last):
  File "deploy.py", line 43, in <module>
    main()
  File "deploy.py", line 36, in main
    if op.done() == True:
  File "/home/rosariod/.virtualenv/automl/lib/python3.6/site-packages/google/api_core/operation.py", line 170, in done
    self._refresh_and_update(retry)
  File "/home/rosariod/.virtualenv/automl/lib/python3.6/site-packages/google/api_core/operation.py", line 157, in _refresh_and_update
    self._operation = self._refresh(retry=retry)
TypeError: _refresh_grpc() got an unexpected keyword argument 'retry'

It seems like it sets _refresh_grpc as self._refresh for the Operation object https://github.com/googleapis/python-api-core/blob/master/google/api_core/operation.py#L299 but when _refresh_and_update is called by done, it gets and passes down to _refresh_grpc a retry param https://github.com/googleapis/python-api-core/blob/master/google/api_core/operation.py#L157 that _refresh_grpc doesn't know how to handle https://github.com/googleapis/python-api-core/blob/master/google/api_core/operation.py#L251 causing the error above.

It might be that the retry param could be correctly handled when the Operation object is created by from_gapic because in that case self._refresh is set to operations_client.get_operation https://github.com/googleapis/python-api-core/blob/master/google/api_core/operation.py#L325 which might be aware of the retry param but doesn't seem to be the case for from_grpc and from_http_json.

Activity

  1. busunkim96 commented on Oct 6, 2020

    @busunkim96
    Contributor

    Hi @rodis,

    Thanks for filing an issue.

    1. Which versions of google-api-core and google-cloud-automl are you using?
    2. When did you first notice this behavior?
    3. Can you show us a bit of the code you're using?
  2. rodis commented on Oct 6, 2020

    @rodis
    Author

    hi @busunkim96

    1. versions
      google-api-core (1.22.4)
      google-cloud-automl (2.0.0)

    2. I just started to use the google-api-core library and I run into the issue as I started to use the from_grpc function

    3. little extract from my code

    SCOPE = 'https://www.googleapis.com/auth/cloud-platform'
    SERVICE_ENDPOINT = 'automl.googleapis.com'
    
    def main():
        creds = service_account.Credentials.from_service_account_file(CREDS_FILE)
        scoped_credentials = creds.with_scopes([SCOPE])
        request = google_auth_transport_requests.Request()
        channel = google_auth_transport_grpc.secure_authorized_channel(
                scoped_credentials, request, SERVICE_ENDPOINT)
        stub = operations_pb2.OperationsStub(channel)
        op = from_grpc(
                operations_pb2.Operation(name=OPERATION),
                stub,
                Model
                )
    
        if op.done() == True:
            sys.exit(0)
  3. busunkim96 commented on Oct 7, 2020

    @busunkim96
    Contributor

    Is there a specific reason you're constructing channels and operations manually? It's possible to use the client library to fetch operations:

    https://github.com/googleapis/python-automl/blob/v2.0.0/samples/snippets/get_operation_status.py

    def get_operation_status(operation_full_id):
        """Get operation status."""
        # [START automl_get_operation_status]
        from google.cloud import automl
    
        # TODO(developer): Uncomment and set the following variables
        # operation_full_id = \
        #     "projects/[projectId]/locations/us-central1/operations/[operationId]"
    
        client = automl.AutoMlClient()
        # Get the latest state of a long-running operation.
        response = client._transport.operations_client.get_operation(
            operation_full_id
        )
    
        print("Name: {}".format(response.name))
        print("Operation details:")
        print(response)
        # [END automl_get_operation_status]
  4. self-assigned this
    on Oct 7, 2020
  5. rodis commented on Oct 7, 2020

    @rodis
    Author

    Hi @busunkim96, thanks for your reply.
    Isn't that more or less what from_gapic does? https://github.com/googleapis/python-api-core/blob/master/google/api_core/operation.py#L326
    I guess I could but It feels like client._transport.operations_client.get_operation exposes me to too many internal details of the AutoML library that I shouldn't know about. Wouldn't that make my script rely on an internal variable _transport with a bunch of other details that from_gapic is taking care of for me?

  6. busunkim96 commented on Oct 8, 2020

    @busunkim96
    Contributor

    That's a fair point. client.transport used to be public and I'm not quite sure what prompted the change. I opened googleapis/gapic-generator-python#640

    As for from_grpc, I'll take a closer look today and get back to you.

  7. rodis commented on Oct 8, 2020

    @rodis
    Author

    @busunkim96 Thank you.

  8. busunkim96 commented on Oct 10, 2020

    @busunkim96
    Contributor

    Hi @rodis,

    The next release of google-cloud-automl will have a public property transport (see change to library templates in googleapis/gapic-generator-python@13cddda). Please use the operations client via _transport for now and switch to transport once the release is made.

    I think your assessment that _refresh_grpc() doesn't know what to do with refresh is correct. The problem was likely introduced with 14f1f34#diff-6e22f95d11fd4cc631b3f0f432433561.

  9. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    triage meI really want to be triaged.
    on Oct 10, 2020
  10. self-assigned this
    on Dec 14, 2020
  11. added a commit that references this issue on Dec 14, 2020
    276939c
  12. added a commit that references this issue on Dec 14, 2020
    7a38243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions