Skip to content

Commit e31cf92

Browse files
committed
Merge branch '5.0' into bolt-utc-datetimes-refactoring
2 parents a7d3ae4 + 2b4f1c7 commit e31cf92

File tree

7 files changed

+134
-79
lines changed

7 files changed

+134
-79
lines changed

neo4j/_codec/hydration/v1/hydration_handler.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@ def __init__(self):
6363

6464
def hydrate_node(self, id_, labels=None,
6565
properties=None, element_id=None):
66+
assert isinstance(self.graph, Graph)
6667
# backwards compatibility with Neo4j < 5.0
6768
if element_id is None:
6869
element_id = str(id_)
6970

7071
try:
7172
inst = self.graph._nodes[element_id]
7273
except KeyError:
73-
inst = self.graph._nodes[element_id] = Node(
74-
self.graph, element_id, id_, labels, properties
75-
)
74+
inst = Node(self.graph, element_id, id_, labels, properties)
75+
self.graph._nodes[element_id] = inst
76+
self.graph._legacy_nodes[id_] = inst
7677
else:
7778
# If we have already hydrated this node as the endpoint of
7879
# a relationship, it won't have any labels or properties.
@@ -112,9 +113,11 @@ def hydrate_unbound_relationship(self, id_, type_, properties=None,
112113
inst = self.graph._relationships[element_id]
113114
except KeyError:
114115
r = self.graph.relationship_type(type_)
115-
inst = self.graph._relationships[element_id] = r(
116+
inst = r(
116117
self.graph, element_id, id_, properties
117118
)
119+
self.graph._relationships[element_id] = inst
120+
self.graph._legacy_relationships[id_] = inst
118121
return inst
119122

120123
def hydrate_path(self, nodes, relationships, sequence):
@@ -139,14 +142,6 @@ def hydrate_path(self, nodes, relationships, sequence):
139142
last_node = next_node
140143
return Path(*entities)
141144

142-
def _hydrate(self, value):
143-
pass
144-
145-
def _dehydrate(self, value):
146-
raise NotImplementedError(
147-
"GraphHydrationHandler cannot be used for dehydration."
148-
)
149-
150145

151146
class HydrationHandler(HydrationHandlerABC):
152147
def __init__(self):

neo4j/graph/__init__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ class Graph:
4444

4545
def __init__(self):
4646
self._nodes = {}
47+
self._legacy_nodes = {} # TODO: 6.0 - remove
4748
self._relationships = {}
49+
self._legacy_relationships = {} # TODO: 6.0 - remove
4850
self._relationship_types = {}
49-
self._node_set_view = EntitySetView(self._nodes)
50-
self._relationship_set_view = EntitySetView(self._relationships)
51+
self._node_set_view = EntitySetView(self._nodes, self._legacy_nodes)
52+
self._relationship_set_view = EntitySetView(self._relationships,
53+
self._legacy_relationships)
5154

5255
@property
5356
def nodes(self):
@@ -176,8 +179,9 @@ class EntitySetView(Mapping):
176179
""" View of a set of :class:`.Entity` instances within a :class:`.Graph`.
177180
"""
178181

179-
def __init__(self, entity_dict):
182+
def __init__(self, entity_dict, legacy_entity_dict):
180183
self._entity_dict = entity_dict
184+
self._legacy_entity_dict = legacy_entity_dict # TODO: 6.0 - remove
181185

182186
def __getitem__(self, e_id):
183187
# TODO: 6.0 - remove this compatibility shim
@@ -186,14 +190,7 @@ def __getitem__(self, e_id):
186190
"Accessing entities by an integer id is deprecated, "
187191
"use the new style element_id (str) instead"
188192
)
189-
if isinstance(e_id, float) and int(e_id) == e_id:
190-
# Non-int floats would always fail for legacy IDs
191-
e_id = int(e_id)
192-
elif isinstance(e_id, complex) and int(e_id.real) == e_id:
193-
# complex numbers with imaginary parts or non-integer real
194-
# parts would always fail for legacy IDs
195-
e_id = int(e_id.real)
196-
e_id = str(e_id)
193+
return self._legacy_entity_dict[e_id]
197194
return self._entity_dict[e_id]
198195

199196
def __len__(self):

testkitbackend/test_config.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
"Optimization:PullPipelining": true,
5555
"Optimization:ResultListFetchAll": "The idiomatic way to cast to list is indistinguishable from iterating over the result.",
5656

57-
"Detail:NullOnMissingId": true,
58-
5957
"ConfHint:connection.recv_timeout_seconds": true,
6058

6159
"Backend:RTFetch": true,

tests/unit/common/codec/hydration/v1/test_graph_hydration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_can_hydrate_node_structure(self, hydration_scope):
4141
assert isinstance(alice, Node)
4242
with pytest.warns(DeprecationWarning, match="element_id"):
4343
assert alice.id == 123
44-
# for backwards compatibility, the driver should compy the element_id
44+
# for backwards compatibility, the driver should compute the element_id
4545
assert alice.element_id == "123"
4646
assert alice.labels == {"Person"}
4747
assert set(alice.keys()) == {"name"}
@@ -58,7 +58,7 @@ def test_can_hydrate_relationship_structure(self, hydration_scope):
5858
assert rel.start_node.id == 456
5959
with pytest.warns(DeprecationWarning, match="element_id"):
6060
assert rel.end_node.id == 789
61-
# for backwards compatibility, the driver should compy the element_id
61+
# for backwards compatibility, the driver should compute the element_id
6262
assert rel.element_id == "123"
6363
assert rel.start_node.element_id == "456"
6464
assert rel.end_node.element_id == "789"

tests/unit/common/codec/hydration/v2/test_graph_hydration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_can_hydrate_relationship_structure(self, hydration_scope):
5858
assert rel.start_node.id == 456
5959
with pytest.warns(DeprecationWarning, match="element_id"):
6060
assert rel.end_node.id == 789
61-
# for backwards compatibility, the driver should compy the element_id
61+
# for backwards compatibility, the driver should compute the element_id
6262
assert rel.element_id == "abc"
6363
assert rel.start_node.element_id == "def"
6464
assert rel.end_node.element_id == "ghi"

tests/unit/common/test_record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def test_data_relationship():
288288
gh = hydration_scope._graph_hydrator
289289
alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
290290
bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
291-
alice_knows_bob = gh.hydrate_relationship(1, alice._id, bob._id, "KNOWS",
291+
alice_knows_bob = gh.hydrate_relationship(1, 1, 2, "KNOWS",
292292
{"since": 1999})
293293
record = Record(zip(["a", "b", "r"], [alice, bob, alice_knows_bob]))
294294
assert record.data() == {

0 commit comments

Comments
 (0)