opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
359 stars 178 forks source link

[BUG] 2.4.0 introduces hard dependency on aiohttp #592

Closed anr-tonic closed 1 year ago

anr-tonic commented 1 year ago

What is the bug?

Traceback (most recent call last):
  File "/app/logshipper.py", line 14, in <module>
    import opensearchpy
  File "/app/opensearchpy/__init__.py", line 47, in <module>
    from ._async.*** import AsyncOpenSearch
  File "/app/opensearchpy/_async/***/__init__.py", line 44, in <module>
    from ..transport import AsyncTransport, TransportError
  File "/app/opensearchpy/_async/transport.py", line 35, in <module>
    from opensearchpy.connection.base import Connection
  File "/app/opensearchpy/connection/__init__.py", line 30, in <module>
    from .http_async import AsyncHttpConnection
  File "/app/opensearchpy/connection/http_async.py", line 19, in <module>
    from .._async._extra_imports import aiohttp, aiohttp_exceptions  *** type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/opensearchpy/_async/_extra_imports.py", line 43, in <module>
    import aiohttp
ModuleNotFoundError: No module named 'aiohttp'

Looks like originating from this change: https://github.com/opensearch-project/opensearch-py/pull/563/files#diff-0ce918db323e76243e4d256deb3f7f8f173c3166a1cea914752b1761f1b0442f

How can one reproduce the bug?

Install opensearch-py==2.4.0 w/o aiohttp and attempt to import it

~ (venv:opensearch-test) $ pip install opensearch-py==2.4.0
Collecting opensearch-py==2.4.0
  Downloading opensearch_py-2.4.0-py2.py3-none-any.whl (258 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 258.4/258.4 kB 2.7 MB/s eta 0:00:00
Collecting requests<3.0.0,>=2.4.0
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 kB 4.6 MB/s eta 0:00:00
Collecting urllib3>=1.26.18
  Downloading urllib3-2.1.0-py3-none-any.whl (104 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 104.6/104.6 kB 5.8 MB/s eta 0:00:00
Collecting certifi>=2022.12.07
  Downloading certifi-2023.7.22-py3-none-any.whl (158 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 158.3/158.3 kB 7.0 MB/s eta 0:00:00
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting python-dateutil
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.3.2-cp39-cp39-macosx_11_0_arm64.whl (120 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 120.4/120.4 kB 6.5 MB/s eta 0:00:00
Installing collected packages: urllib3, six, idna, charset-normalizer, certifi, requests, python-dateutil, opensearch-py
Successfully installed certifi-2023.7.22 charset-normalizer-3.3.2 idna-3.4 opensearch-py-2.4.0 python-dateutil-2.8.2 requests-2.31.0 six-1.16.0 urllib3-2.1.0

[notice] A new release of pip available: 22.2.1 -> 23.3.1
[notice] To update, run: pip install --upgrade pip
~  (venv:opensearch-test) $ python -c "import opensearchpy"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/anr/.venvs/opensearch-test/lib/python3.9/site-packages/opensearchpy/__init__.py", line 47, in <module>
    from ._async.client import AsyncOpenSearch
  File "/Users/anr/.venvs/opensearch-test/lib/python3.9/site-packages/opensearchpy/_async/client/__init__.py", line 44, in <module>
    from ..transport import AsyncTransport, TransportError
  File "/Users/anr/.venvs/opensearch-test/lib/python3.9/site-packages/opensearchpy/_async/transport.py", line 35, in <module>
    from opensearchpy.connection.base import Connection
  File "/Users/anr/.venvs/opensearch-test/lib/python3.9/site-packages/opensearchpy/connection/__init__.py", line 30, in <module>
    from .http_async import AsyncHttpConnection
  File "/Users/anr/.venvs/opensearch-test/lib/python3.9/site-packages/opensearchpy/connection/http_async.py", line 19, in <module>
    from .._async._extra_imports import aiohttp, aiohttp_exceptions  # type: ignore
  File "/Users/anr/.venvs/opensearch-test/lib/python3.9/site-packages/opensearchpy/_async/_extra_imports.py", line 43, in <module>
    import aiohttp
ModuleNotFoundError: No module named 'aiohttp'

What is the expected behavior?

Importing opensearch w/o aiohttp installed works

What is your host/environment?

Operating system, version.

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Add any other context about the problem.

dblock commented 1 year ago

Yep :(

This is my bad. It's not supposed to do that, I'll take care of it first thing tomorrow unless someone beats me to it.

We definitely need an integration test that exercises the client independently - I just ran into this in https://github.com/dblock/opensearch-python-client-demo.

dblock commented 1 year ago

Fix in https://github.com/opensearch-project/opensearch-py/pull/594.

dblock commented 1 year ago

Tested 2.4.1 on https://github.com/dblock/opensearch-python-client-demo successfully.