Closed adrienrougny closed 3 years ago
I think this is causing an issue for my current project.
We previously had code that looked (something) like this:
import py2neo
g = py2neo.Graph("my_graph_address")
result = g.run("match (n :a_label) return n limit 10")
raw_sg = result.to_subgraph()
nodes = [n for n in raw_sg.nodes]
rels = [r for r in raw_sg.relationships]
further_processing(nodes)
further_processing(rels)
I've just upgraded to 3.9, and it looks like this is no longer working, I only get the last record back in raw_sg
, meaning the full set of nodes/relationships cannot be returned. I think we can probably code around it or fall back to an earlier version of Python (thanks for filing the issue @Adrienrougny, I suspect I wouldn't have figured this out otherwise!).
I agree that the __or__()
of dict
does look like it's getting called, as if I run something like this:
raw_result = g.run("[a query]")
sg_list = []
for result in raw_result:
new_sg = result.to_subgraph()
sg_list.append(new_sg)
sg_list[0].__or__(sg_list[1])
I get a dict
back, and not a Subgraph
as I would expect.
This has already been fixed in https://github.com/technige/py2neo/commit/881cd3fcd05538d4dff1409d72135353446ec117, although it has not yet been released.
Oh brill, thanks! I've fallen back to 3.8 for now so it's not hugely pressing, but do you know when you plan to do the next release? In either case, thanks very much for the response and the package!@
Hopefully not long before I do another one, though I don't have a date in mind quite yet.
I actually decided to release tonight! So your fix should be live in 2021.0.0.
Python 3.9 introduced merge (|) and update (|=) operators to the dict class. When merging nodes and relationships in Python 3.9, it seems that it is the
__or__
/__ior__
method of the dict class that is called rather the__or__
method of the Subgraph class, because of inheritance and MRO.