Fixed : Unable to install Memgraph with python support on Ubuntu 20.04

Hi
I am trying to use memgraph with python support on ubuntu 20.04 freshly installed.
The setup is:
python3.8
mgclient lib built without any trouble
pymgclient installed with pip3 (install is not possible from from due to a missing CMakefile.txt)

I have a simple python module. And all is working on Ubuntu 18.04.
My issue is on ubuntu 20.04.

I get this error, i am really lost !

need help please.
Jeremie

^[[A[2021-05-27 19:01:43.075] [memgraph_log] [error] Unable to load module “/usr/lib/memgraph/query_modules/mymodule.py”; Traceback (most recent call last):
File “/usr/lib/memgraph/query_modules/mymodule.py”, line 80, in
def myproc(ctx: mgp.ProcCtx,
File “/usr/lib/memgraph/python_support/mgp.py”, line 797, in read_proc
mgp_proc.add_result(name, typing_to_cypher_type(type))
File “/usr/lib/memgraph/python_support/mgp.py”, line 630, in _typing_to_cypher_type
if isinstance(None, type_args):
File “/usr/lib/python3.8/typing.py”, line 769, in instancecheck
return self.subclasscheck(type(obj))
File “/usr/lib/python3.8/typing.py”, line 777, in subclasscheck
raise TypeError(“Subscripted generics cannot be used with”
TypeError: Subscripted generics cannot be used with class and instance checks

In my module, myproc is defined as (ok on 18.04) :

@mgp.read_proc
def myproc(ctx: mgp.ProcCtx,
source: mgp.Vertex,
depth_limit: mgp.Nullable[int] = None
) → mgp.Record(mylist=mgp.Nullable[mgp.List[int]]):

1 Like

Hi @jeremos!

Which version of Memgraph are you running?

Yea, it seems like a bug in the Python query modules code inside Memgraph. Could you please paste the entire myproc implementation (or just the critical part) + some representative subset of a dataset? To be able to pinpoint the exact problem.

Also, you can inspect /usr/lib/memgraph/python_support/mgp.py, it’s a local file on your file system and print(type_args) what actually is.

But this seems like something solvable, we’ll try to figure it out quickly :smiley:

Best,
buda

Hi @buda
We are using the last memgraph1.5-ce freshly released (today) ?

Here a sample code for myproc.
@mgp.read_proc
def foo(ctx: mgp.ProcCtx,
source: mgp.Vertex,
depth_limit: mgp.Nullable[int] = None
) → mgp.Record(ids=mgp.Nullable[mgp.List[int]]):
gres = list(bfs_tree(
MemgraphMultiDiGraph(ctx=ctx), source, reverse=False,
depth_limit=depth_limit))
gres2 = list(filter(lambda e: e.labels[0] == ‘bar’, gres))
return mgp.Record(ids=gres2)

Thank you for your help. After working with Neo4j and redisgraph, we think Memgraph is very powerfull and the python support with networkX is just amazing :slight_smile:

1 Like

I forgot : this error appears when memgraph starts without any data in the DB

Great!

I’ve managed to recreate with:

import mgp
@mgp.read_proc
def myproc(ctx: mgp.ProcCtx,
        source: mgp.Vertex,
        depth_limit: mgp.Nullable[int] = None
        ) -> mgp.Record(mylist=mgp.Nullable[mgp.List[int]]):
    return mgp.Record(mylist=[])

mgp.py prints:

Memgraph 1.5 with --also-log-to-stderr and --log-level=TRACE flags.
Keep in mind that for each change in the mgp.py file the entire Memgraph has to be restarted.

Still not sure exactly what is going on, it seems that something is wrong with the return type…

Still not sure how to properly fix the problem (seems very specific to the Python types), but the whole script loads if the return type is mgp.Record(mylist=mgp.List[int]), and I think that’s ok in your case because a list is always returned?

Yes, we return a list of int. (using a custom bfs_tree to grab successors and predecesors)…

But without our custom dev the issue also appears with default py modules :

1 Like

Yep, it’s 100% a bug. Thank you very much for reporting! We’ll try to come up with the proper fix.

Glad to hear that you like Memgraph :muscle:

In addition to the Python query modules, we also significantly improved the overall Python support. gqlalchemy might be interesting (also released a couple of days ago :smiley:).

The entire block of code from mgp.py:624 to mgp.py:642 doesn’t work on any of [python3.8, python3.9, python3.10]. I think the best solution is to completely delete that chunk of code.

Screenshot from 2021-05-27 23-33-19
The same happens for all other versions from 3.5 to 3.10.

Feel free to do that locally (for now), to avoid similar issues with other scrips.

I’ll consult with the team and provide the best possible fix as soon as possible.

Thank you so much!

thank you very much for this quick fix.
I will try tomorrow memgraph V1.5 and check if the segfault occurs again (other issue opened).

next feedback tomorrow morning

jeremie

1 Like

Here is the proper fix:

-            if isinstance(None, type_args):
-                types = tuple(t for t in type_args if not isinstance(None, t))
+            # isinstance doesn't work here because subscripted generics cannot
+            # be used with class and instance checks. type comparison should be
+            # fine because subclasses are not used.
+            if type(None) in type_args:
+                types = tuple(t for t in type_args if t is not type(None))  # noqa E721

It will be included in the next release :smiley:

Someone from the team will soon jump on the segfault issue :smiley: