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

Current version of Collection on pypi throws exception if one checks if a document exists #119

Closed larsborn closed 5 years ago

larsborn commented 5 years ago

Mainly putting this in here if someone is running into similar issues.

The collection objects on version 1.3.1 (most recent version pf pypi by the time of writing) throws a KeyError exception when one checks for document existence:

if my_key in db['my_collection']:
    [...]

Intended behavior would imho be to gracefully return False if the document does not exist. This behavior seems to be already implemented in the more recent version 1.3.2. through a new __contains__ method on the Collection class. Resolving #105 would solve this issue.

A current workaround obviously is:

exists = True
try:
    my_key in db['my_collection']
except KeyError:
    exists: False
if exists:
    [...]

Potentially related #113.

tariqdaouda commented 5 years ago

Yes is has been implemented in the 1.3.2 but only with the document key. I could improve it to also work with the document itself.

Cheers!