Skip to content

Commit 9ede7eb

Browse files
authored
Merge pull request #270 from technige/1.7-non-string-keys
[1.7.1] Raise TypeError for non-string dictionary keys
2 parents f381321 + 77d0dcc commit 9ede7eb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

neo4j/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def dehydrate_(obj):
125125
elif isinstance(obj, (list, map_type)):
126126
return list(map(dehydrate_, obj))
127127
elif isinstance(obj, dict):
128+
if any(not isinstance(key, string) for key in obj.keys()):
129+
raise TypeError("Non-string dictionary keys are not supported")
128130
return {key: dehydrate_(value) for key, value in obj.items()}
129131
else:
130132
raise TypeError(obj)

test/integration/test_types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def test_map(self):
103103
result = session.run("RETURN {one: 'eins', two: 'zwei', three: 'drei'}")
104104
self.assertEqual(result.single().value(), {"one": "eins", "two": "zwei", "three": "drei"})
105105

106+
def test_non_string_map_keys(self):
107+
with self.driver.session() as session:
108+
with self.assertRaises(TypeError):
109+
_ = session.run("RETURN $x", x={1: 'eins', 2: 'zwei', 3: 'drei'})
110+
106111

107112
class GraphTypeOutputTestCase(DirectIntegrationTestCase):
108113

0 commit comments

Comments
 (0)