Skip to content

Commit f0fa64d

Browse files
fixed label issue for last node when hydrating relationship (#411)
1 parent dc1695c commit f0fa64d

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

neo4j/graph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def hydrate_node(self, n_id, n_labels=None, properties=None):
8484
# a relationship, it won't have any labels or properties.
8585
# Therefore, we need to add the ones we have here.
8686
if n_labels:
87-
inst._labels = frozenset(inst._labels & set(n_labels))
87+
inst._labels = inst._labels.union(n_labels) # frozen_set
8888
if properties:
8989
inst._properties.update(properties)
9090
return inst
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2020 "Neo4j,"
5+
# Neo4j Sweden AB [http://neo4j.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
22+
import pytest
23+
24+
from neo4j.graph import (
25+
Node,
26+
Relationship,
27+
Graph,
28+
Path,
29+
)
30+
from neo4j.exceptions import Neo4jError
31+
32+
33+
def test_result_graph_instance(session):
34+
# python -m pytest tests/integration/test_result_graph.py -s -v -k test_result_graph_instance
35+
result = session.run("RETURN 1")
36+
graph = result.graph()
37+
38+
assert isinstance(graph, Graph)
39+
40+
41+
def test_result_graph_case_1(session):
42+
# python -m pytest tests/integration/test_result_graph.py -s -v -k test_result_graph_case_1
43+
result = session.run("CREATE (n1:Person:LabelTest1 {name:'Alice'})-[r1:KNOWS {since:1999}]->(n2:Person:LabelTest2 {name:'Bob'}) RETURN n1, r1, n2")
44+
graph = result.graph()
45+
assert isinstance(graph, Graph)
46+
47+
node_view = graph.nodes
48+
relationships_view = graph.relationships
49+
50+
for node in node_view:
51+
name = node["name"]
52+
if name == "Alice":
53+
assert node.labels == frozenset(["Person", "LabelTest1"])
54+
elif name == "Bob":
55+
assert node.labels == frozenset(["Person", "LabelTest2"])
56+
else:
57+
pytest.fail("should only contain 2 nodes, Alice and Bob. {}".format(name))
58+
59+
for relationship in relationships_view:
60+
since = relationship["since"]
61+
assert since == 1999
62+
assert relationship.type == "KNOWS"

0 commit comments

Comments
 (0)