Commit 91748123 authored by Leifur Halldor Asgeirsson's avatar Leifur Halldor Asgeirsson
Browse files

nested deserialiazation

parent a4deee6a
......@@ -137,8 +137,12 @@ class Session(connection.AbstractConnection):
async def _receive(self, async_iter, response_queue):
async for result in async_iter:
if (isinstance(result, dict) and
result.get('type', '') in ['vertex', 'edge']):
def _deserialize_result(self, result):
if isinstance(result, dict):
if result.get('type', '') in ['vertex', 'edge']:
hashable_id = self._get_hashable_id(result['id'])
current = self.current.get(hashable_id, None)
if not current:
......@@ -151,10 +155,15 @@ class Session(connection.AbstractConnection):
current.source = GenericVertex() = GenericVertex()
element = current.__mapping__.mapper_func(result, current)
return element
for key in result:
result[key] = self._deserialize_result(result[key])
return result
elif isinstance(result, list):
return [self._deserialize_result(item) for item in result]
return result
# Creation API
def add(self, *elements):
......@@ -22,6 +22,8 @@ import pytest
from goblin import element
from goblin.traversal import bindprop
from gremlin_python.process.graph_traversal import __
async def test_session_close(session):
......@@ -326,3 +328,20 @@ class TestTraversalApi:
'name', 'leif').one_or_none()
one = await session.g.V(
assert one == 1
async def test_deserialize_nested_map(self, session, person_class):
async with session:
await session.g.addV('person').property(, 'leif').property('place_of_birth', 'detroit').one_or_none()
await session.g.addV('person').property(, 'David').property(
person_class.nicknames, 'davebshow').property(
person_class.nicknames, 'Dave').one_or_none()
resp = await (session.g.V().hasLabel('person')._as('x').valueMap()._as('y')
.select('x', 'y').fold().one_or_none())
for item in resp:
assert isinstance(item['x'], person_class)
assert isinstance(item['y'], dict)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment