neomodel
neomodel copied to clipboard
async iterating over nodes is not working
Expected Behavior (Mandatory)
It is possible to iterate over nodes in async style
Actual Behavior (Mandatory)
It is not possible to iterate over nodes in async style. You have to fetch all nodes to memory before iteration
How to Reproduce the Problem
Run code below
Simple Example
import asyncio
import neomodel
import neomodel.config
from neomodel import AsyncStructuredNode, IntegerProperty
neomodel.config.DATABASE_URL = 'bolt://neo4j:12345678@neo4j:7687'
class SomeNode(AsyncStructuredNode):
number = IntegerProperty(required=True)
async def delete():
nodes = await SomeNode.nodes
for node in nodes:
await node.delete()
async def main():
# clean up
await delete()
for i in range(10):
await SomeNode(number=i).save()
nodes = await SomeNode.nodes
assert isinstance(nodes, list)
assert all(isinstance(i, SomeNode) for i in nodes)
try:
for i in SomeNode.nodes:
# make some iteration
print(i)
except Exception as e:
# SomeNode.nodes is not sync iterable as expected
print(e)
try:
async for node in SomeNode.nodes:
print(node)
except Exception as e:
# SomeNode.nodes has __aiter__() method
# but it has a bug at
# neomodel.async_.match line 813
print(e)
# this works fine but this approach is not async as it fetches all nodes before iterating
for node in await SomeNode.nodes:
print(node)
if __name__ == '__main__':
asyncio.run(main())
Specifications (Mandatory)
don't know what I should write here
Currently used versions
Versions
- OS: linux, 3.10.14-slim
- Library:5.3.0 [extras]
- Neo4j:5.19.0 community