googleapis / python-api-core

https://googleapis.dev/python/google-api-core/latest
Apache License 2.0
123 stars 88 forks source link

Backward compatible import of retry_async does not work in 2.16.0 #586

Closed potiuk closed 10 months ago

potiuk commented 10 months ago

The code aimed to maintain backwards compatibity when importing retry_async did not work when the .

Environment details

Name: google-api-core
Version: 2.16.0
Summary: Google API client core library
Home-page: https://github.com/googleapis/python-api-core
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /usr/local/lib/python3.8/site-packages
Requires: google-auth, googleapis-common-protos, protobuf, requests
Required-by: google-ads, google-analytics-admin, google-api-python-client, google-cloud-aiplatform, google-cloud-appengine-logging, google-cloud-automl, google-cloud-batch, google-cloud-bigquery, google-cloud-bigquery-datatransfer, google-cloud-bigquery-storage, google-cloud-bigtable, google-cloud-build, google-cloud-compute, google-cloud-container, google-cloud-core, google-cloud-datacatalog, google-cloud-dataflow-client, google-cloud-dataform, google-cloud-dataplex, google-cloud-dataproc, google-cloud-dataproc-metastore, google-cloud-dlp, google-cloud-kms, google-cloud-language, google-cloud-logging, google-cloud-memcache, google-cloud-monitoring, google-cloud-orchestration-airflow, google-cloud-os-login, google-cloud-pubsub, google-cloud-redis, google-cloud-resource-manager, google-cloud-run, google-cloud-secret-manager, google-cloud-spanner, google-cloud-speech, google-cloud-storage, google-cloud-storage-transfer, google-cloud-tasks, google-cloud-texttospeech, google-cloud-translate, google-cloud-videointelligence, google-cloud-vision, google-cloud-workflows, pandas-gbq, sqlalchemy-bigquery

Steps to reproduce

  1. Run pip insall google-api-core==2.15.0
  2. Enter python repl with python
  3. Run from google.api_core.retry_async import AsyncRetry -> this nicely works
  4. Run from google.api_core.retry import AsyncRetry -> this does not work (as expected)
>>> from google.api_core.retry import AsyncRetry
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'AsyncRetry' from 'google.api_core.retry' (/usr/local/lib/python3.8/site-packages/google/api_core/retry.py)
  1. Run pip insall google-api-core==2.16.0
  2. Enter python repl with python
  3. Run from google.api_core.retry_async import AsyncRetry -> this does not work (but should)
>>> from google.api_core.retry_async import AsyncRetry
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'google.api_core.retry_async'
>>> 
  1. Run from google.api_core.retry import AsyncRetry -> this works (as expected)

There was an attempt in #495 to make it work:

In: google/api_core/init.py

# for backwards compatibility, expose async unary retries as google.api_core.retry_async
from .retry import retry_unary_async as retry_async  # noqa: F401

This is aimed to make from google.api_core.retry_async import AsyncRetry works, but importing a module into another modules __init__ does not work the way it is supposed to work.

While there was attempt to even test it in #577, it did not test the right imports:

def test_legacy_imports_retry_unary_async():
    # TODO: Delete this test when when we revert these imports on the
    #       next major version release
    #       (https://github.com/googleapis/python-api-core/issues/576)
    from google.api_core import retry_async  # noqa: F401

The from google.api_core import retry_async works, fine, but from google.api_core.retry_async import AsyncRetry still raises the No module named 'google.api_core.retry_async - bycause of the way how python resolves from.

I guess good solution will be to add back the retry_async as a (mostly empty) submodule and import all the needed classess from the retry_unary_async package

Code example

from google.api_core.retry_async import AsyncRetry
from google.api_core.retry import AsyncRetry

Stack trace

>>> from google.api_core.retry_async import AsyncRetry
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'google.api_core.retry_async'
>>> 

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

parthea commented 10 months ago

Hi @potiuk,

Thanks for reporting this issue. We've released 2.16.1 which has the fix.

https://pypi.org/project/google-api-core/2.16.1/

potiuk commented 10 months ago

Works nicely. 🙇