ArangoDB-Community / pyArango

Python Driver for ArangoDB with built-in validation
https://pyarango.readthedocs.io/en/latest/
Apache License 2.0
238 stars 90 forks source link

Fail to read results of a query returning simple values #198

Closed vgasiunas closed 3 years ago

vgasiunas commented 3 years ago

Example:

res = db.AQLQuery("RETURN COUNT(MyCollection)")
print(res[0])

Results in an error:

  File "/Users/vaidas/.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyArango/query.py", line 118, in __getitem__
    self._developDoc(i)
  File "/Users/vaidas/.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyArango/query.py", line 73, in _developDoc
    collection = self.database[docJson["_id"].split("/")[0]]
TypeError: 'int' object is not subscriptable

Apparently a JSON object is always expected as a result, not a plain integer value.

Alexsaphir commented 3 years ago

Following https://pyarango.readthedocs.io/en/latest/database/#pyArango.database.Database The function return a document(s), if you want a JSON result use res = db.AQLQuery("RETURN COUNT(MyCollection)", rawResults = True)

vgasiunas commented 3 years ago

I see, thanks!