Skip to content

Endless loop when using itertools.batched with an arango query #249

@gelineau

Description

@gelineau

The AQLQuery object in the pyarango library is not compatible with itertools.batched, leading to an endless loop.

When the iterator is exhausted, calling next() raises StopIteration. However, calling next() again on the iterator restarts it, returning the first result instead of raising StopIteration again. This behavior leads itertools.batched to make an infinite loop.

See following example:

import itertools

from pyArango.connection import Connection

print(f"Connecting...")
cnx = Connection(
    arangoURL="http://localhost:8529",
    username="datalake",
    password="datalake",
    timeout=30,
)
db = cnx["datalake"]

# my database contains 12 links
relations = db.AQLQuery(
    f"""
      FOR link IN links
      RETURN link
    """,
    rawResults=True,
)

for batch in itertools.batched(relations, 100):
    print(f"iteration")

The iterator should raise StopIteration consistently when exhausted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions