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

python 3.10 support

Open robertcsapo opened this issue 3 years ago • 3 comments

ImportError: cannot import name 'Iterable' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)

options = {"fields": ["document", "diff", "action"]}
stream = client.stream(doc["ref"], options, on_start, on_error, on_version)
stream.start()
Traceback (most recent call last):
  File "/workspaces/faunadb/github/faunadb-python/example.py", line 3, in <module>
    from faunadb.client import FaunaClient
  File "/workspaces/faunadb/github/faunadb-python/faunadb/client.py", line 19, in <module>
    from faunadb.streams import Subscription
  File "/workspaces/faunadb/github/faunadb-python/faunadb/streams/__init__.py", line 1, in <module>
    from .client import Connection
  File "/workspaces/faunadb/github/faunadb-python/faunadb/streams/client.py", line 12, in <module>
    from hyper import HTTP20Connection
  File "/home/vscode/.local/lib/python3.10/site-packages/hyper/__init__.py", line 11, in <module>
    from .common.connection import HTTPConnection
  File "/home/vscode/.local/lib/python3.10/site-packages/hyper/common/connection.py", line 9, in <module>
    from ..http11.connection import HTTP11Connection
  File "/home/vscode/.local/lib/python3.10/site-packages/hyper/http11/connection.py", line 13, in <module>
    from collections import Iterable, Mapping
ImportError: cannot import name 'Iterable' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)

This is due to hyper, for stream function (http/2) https://github.com/fauna/faunadb-python/blob/1e16d7923cebb442c672db7b392d7f2bccbd825a/faunadb/streams/client.py#L12 https://github.com/fauna/faunadb-python/blob/1e16d7923cebb442c672db7b392d7f2bccbd825a/faunadb/streams/client.py#L48

"This project is no longer maintained! Please use an alternative, such as HTTPX or others. We will not publish further updates for hyper."

https://github.com/python-hyper/hyper

(faunadb-python works with python 3.9)

robertcsapo avatar Jan 09 '22 15:01 robertcsapo

Probably not recommended, but here is a workaround I used to get fauna working on my dev (not production) script. Commented out line 12 from the file ..REDACTED/site-packages/faunadb/streams. #from hyper import HTTP20Connection. Probably will impact other functions, but did make it past the error with collections so far.

tigerrabbit avatar Jan 16 '22 22:01 tigerrabbit

I've replaced hyper with httpx in my fork and it seems to work.

doc = client.query(q.get(q.ref(q.collection("customers"), "101")))

indexes = client.query(q.paginate(q.indexes()))
options = {"fields": ["document", "diff", "action"]}
stream = client.stream(doc["ref"], options, on_start, on_error, on_version)
stream.start()
@robertcsapo ➜ /workspaces/faunadb-python (httpx ✗) $ python example.py 
started stream at 1642450065838000
on_version event at 1642450066010000
Event action: update
Changes made: None

on_version event at 1642450080180000
Event action: update
Changes made: {'lastName': 'GitHub'}

https://github.com/robertcsapo/faunadb-python/commit/a3caa9ab3afdef664a14113943c538f381506ba5#diff-835dd880822e3220bdae3adb6dfc4385cf7e2fc783eb2e2d7ddfa0f3e31566fd

https://github.com/robertcsapo/faunadb-python/blob/httpx/faunadb/streams/client.py

robertcsapo avatar Jan 17 '22 20:01 robertcsapo

Just adding another comment here as Python 3.10 is shipping in more distros, and FaunaDB is the last dependency in several projects of mine to support it...

tweedge avatar Jun 25 '22 21:06 tweedge

For those who need this to work until it gets supported. you can add the following before your fauna imports

import collections.abc
collections.Iterable = collections.abc.Iterable
collections.Mapping = collections.abc.Mapping
collections.MutableSet = collections.abc.MutableSet
collections.MutableMapping = collections.abc.MutableMapping

twobitunicorn avatar Oct 14 '22 14:10 twobitunicorn

Thanks @robertcsapo for the contribution 👏 , apologies all for the delay on official support. It's been added in 4.5.0

Let us know if any issues are encountered during usage.

wildemat avatar Mar 01 '23 02:03 wildemat