Skip to content

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

Closed
@potiuk

Description

@potiuk

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

Environment details

  • OS type and version: Dockerised Debian Bookwork
  • Python version: python --version: 3.8.18
  • pip version: pip --version: 23.3.2
  • google-api-core version: pip show google-api-core
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: [email protected]
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!

Metadata

Metadata

Assignees

Labels

priority: p1Important issue which blocks shipping the next release. Will be fixed prior to 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