Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rodis opened this issue Oct 6, 2020 · 7 comments · Fixed by #115
Closed

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

rodis opened this issue Oct 6, 2020 · 7 comments · Fixed by #115
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@rodis
Copy link

rodis commented Oct 6, 2020

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.

@busunkim96
Copy link
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?

@rodis
Copy link
Author

rodis commented Oct 6, 2020

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)

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Oct 7, 2020
@busunkim96
Copy link
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]

@busunkim96 busunkim96 self-assigned this Oct 7, 2020
@rodis
Copy link
Author

rodis commented Oct 7, 2020

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?

@busunkim96
Copy link
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.

@rodis
Copy link
Author

rodis commented Oct 8, 2020

@busunkim96 Thank you.

@busunkim96
Copy link
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.

@busunkim96 busunkim96 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. labels Oct 10, 2020
@tseaver tseaver self-assigned this Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants