rethinkdb-python icon indicating copy to clipboard operation
rethinkdb-python copied to clipboard

Asyncio not compatible with python 3.10

Open luckydonald opened this issue 4 years ago • 2 comments

Describe the bug The most basic example fails BaseEventLoop.create_connection() got an unexpected keyword argument 'loop'

To Reproduce Steps to reproduce the behavior:

  • install the most recent python
pyenv install 3.10
pyenv use 3.10
  • try to run the async example
async def main():
    r.set_loop_type('asyncio')
    connection = await r.connect(db='test')

    await r.table_create('marvel').run(connection)

Expected behavior It works.

Screenshots

 Traceback (most recent call last):
           File "/Users/luckydonald/.pyenv/versions/3.10.0/lib/python3.10/site-packages/rethinkdb/asyncio_net/net_asyncio.py", line 202, in connect
             self._streamreader, self._streamwriter = yield from asyncio.open_connection(
           File "/Users/luckydonald/.pyenv/versions/3.10.0/lib/python3.10/asyncio/streams.py", line 47, in open_connection
             transport, _ = await loop.create_connection(
         TypeError: BaseEventLoop.create_connection() got an unexpected keyword argument 'loop'
         

System info

  • Python: 3.10.0
  • pip: rethinkdb==2.4.8
  • OS: [macOS Mojave 10.14.6 (18G103)]
  • RethinkDB Version:
Running rethinkdb 2.4.1 (CLANG 11.0.0 (clang-1100.0.33.17))...
Running on Darwin 18.7.0 x86_64

Additional context Add any other context about the problem here.

luckydonald avatar Nov 19 '21 14:11 luckydonald

But it's apparently not only the loop parameter:

  • rethinkdb/asyncio_net/net_asyncio.py", line 202, in connect self._streamreader, self._streamwriter = yield from asyncio.open_connection(
    • TypeError: BaseEventLoop.create_connection() got an unexpected keyword argument 'loop'
  • rethinkdb/asyncio_net/net_asyncio.py", line 232, in connect response = yield from asyncio.wait_for(
    • TypeError: wait_for() got an unexpected keyword argument 'loop'
  • rethinkdb/asyncio_net/net_asyncio.py:229:
    • SyntaxWarning: "is not" with a literal. Did you mean "!="?
  • site-packages/rethinkdb/ast.py", line 87, in expr elif isinstance(val, collections.Callable):
    • AttributeError: module 'collections' has no attribute 'Callable'

luckydonald avatar Nov 19 '21 14:11 luckydonald

Bump, running into this now.

Also... asyncio_net/net_asyncio.py, asyncio.get_event_loop is being deprecated as well. Should be using asyncio.get_running_loop per https://docs.python.org/3/library/asyncio-eventloop.html

stephanelsmith avatar Mar 01 '22 21:03 stephanelsmith

Umm. Not sure if the library is still alive. But in any case, here's what I get when trying to use it with asyncio on python 3.11:

In [1]: from rethinkdb import r

In [2]: r.set_loop_type('asyncio')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 r.set_loop_type('asyncio')

File ~/miniforge3/envs/py311/lib/python3.11/site-packages/rethinkdb/__init__.py:65, in RethinkDB.set_loop_type(self, library)
     63 def set_loop_type(self, library=None):
     64     if library == "asyncio":
---> 65         from rethinkdb.asyncio_net import net_asyncio
     66         self.connection_type = net_asyncio.Connection
     68     if library == "gevent":

File ~/miniforge3/envs/py311/lib/python3.11/site-packages/rethinkdb/asyncio_net/net_asyncio.py:42
     38 pResponse = ql2_pb2.Response.ResponseType
     39 pQuery = ql2_pb2.Query.QueryType
---> 42 @asyncio.coroutine
     43 def _read_until(streamreader, delimiter):
     44     """Naive implementation of reading until a delimiter"""
     45     buffer = bytearray()

AttributeError: module 'asyncio' has no attribute 'coroutine'

antony66 avatar Sep 25 '23 15:09 antony66

We now have #294 for the Python 3.11 issue.

But there are a bunch of other PRs open that might carry the change -- I guess they should be looked at first.

srh avatar Oct 04 '23 20:10 srh

@antony66 the library is still alive....kinda. We're quite busy and find little time to work on the project that has been abandoned for a long time. Furthermore, the changes in the python ecosystem are happening quite fast.

We're working on supporting python 3.10+ and drop support for python 2.XX . See the branch https://github.com/rethinkdb/rethinkdb-python/tree/lsabi/commands

To a basic implementation (asyncio only) we're lacking the last checks here and there on the commands. The rest should be working. If you have knowledge and time enough, feel free to contribute on this branch

lsabi avatar Oct 04 '23 20:10 lsabi

asyncio_net/net_asyncio.py, asyncio.get_event_loop is being deprecated as well. Should be using asyncio.get_running_loop per

Thanks for the info. Since get_running_loop is new in Python 3.7 and get_event_loop is not broken yet, I'm going to not update that just yet. (I'm trying to make the minimal set of PR's to get 3.10 and 3.11 more working right now.)

srh avatar Oct 04 '23 20:10 srh

@lsabi let’s see if I can help

antony66 avatar Oct 05 '23 20:10 antony66

@lsabi I'm having this very issue. I would like to use this driver with python3.11 and onwards.

Is there anythingI can help with? Maybe implement some of the changes suggested in the PR.

fdemian avatar Nov 02 '23 04:11 fdemian

@fdemian This is now already fixed in the master branch and you could build and use the driver off that yourself. I also created #301 to nag the devs into cutting a new release with these fixes.

srh avatar Nov 02 '23 05:11 srh

Closing as this has now been fixed with the latest release https://github.com/rethinkdb/rethinkdb-python/releases/tag/v2.4.10

lsabi avatar Nov 14 '23 21:11 lsabi