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

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

Closed
potiuk opened this issue Jan 30, 2024 · 2 comments · Fixed by #587
Closed

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

potiuk opened this issue Jan 30, 2024 · 2 comments · Fixed by #587
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@potiuk
Copy link

potiuk commented Jan 30, 2024

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!

@parthea parthea added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Jan 30, 2024
potiuk added a commit to potiuk/airflow that referenced this issue Jan 30, 2024
There is a backwards-incompatible change in
google.api_core.retry.AsyncRetry imports.

In 2.16.0 version of google-api-core, AsyncRetry was moved to
google.api_core.retry_unary_async and backwards compatibility impots
were not haandling the case of:
`from google.api_core.retry_async imprt AsyncRetry`

The issue is tracked in googleapis/python-api-core#586

Until it is solved, we need to handle both cases, because one works
before and one after 2.16.0.

But there is no import that works for both.
potiuk added a commit to apache/airflow that referenced this issue Jan 30, 2024
There is a backwards-incompatible change in
google.api_core.retry.AsyncRetry imports.

In 2.16.0 version of google-api-core, AsyncRetry was moved to
google.api_core.retry_unary_async and backwards compatibility impots
were not haandling the case of:
`from google.api_core.retry_async imprt AsyncRetry`

The issue is tracked in googleapis/python-api-core#586

Until it is solved, we need to handle both cases, because one works
before and one after 2.16.0.

But there is no import that works for both.
@parthea
Copy link
Collaborator

parthea commented Jan 31, 2024

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
Copy link
Author

potiuk commented Jan 31, 2024

Works nicely. 🙇

kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Jul 19, 2024
There is a backwards-incompatible change in
google.api_core.retry.AsyncRetry imports.

In 2.16.0 version of google-api-core, AsyncRetry was moved to
google.api_core.retry_unary_async and backwards compatibility impots
were not haandling the case of:
`from google.api_core.retry_async imprt AsyncRetry`

The issue is tracked in googleapis/python-api-core#586

Until it is solved, we need to handle both cases, because one works
before and one after 2.16.0.

But there is no import that works for both.

GitOrigin-RevId: 762f5447418e34d3472d9f23124546c0b6d995ae
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Sep 20, 2024
There is a backwards-incompatible change in
google.api_core.retry.AsyncRetry imports.

In 2.16.0 version of google-api-core, AsyncRetry was moved to
google.api_core.retry_unary_async and backwards compatibility impots
were not haandling the case of:
`from google.api_core.retry_async imprt AsyncRetry`

The issue is tracked in googleapis/python-api-core#586

Until it is solved, we need to handle both cases, because one works
before and one after 2.16.0.

But there is no import that works for both.

GitOrigin-RevId: 762f5447418e34d3472d9f23124546c0b6d995ae
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Nov 8, 2024
There is a backwards-incompatible change in
google.api_core.retry.AsyncRetry imports.

In 2.16.0 version of google-api-core, AsyncRetry was moved to
google.api_core.retry_unary_async and backwards compatibility impots
were not haandling the case of:
`from google.api_core.retry_async imprt AsyncRetry`

The issue is tracked in googleapis/python-api-core#586

Until it is solved, we need to handle both cases, because one works
before and one after 2.16.0.

But there is no import that works for both.

GitOrigin-RevId: 762f5447418e34d3472d9f23124546c0b6d995ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to 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.

3 participants