Skip to content

Catching KeyError instead of IndexError #131

@kootenpv

Description

@kootenpv

For example:

I created some indexed objects, but in the case one does not exist and one tries to use "single" (index['user_id']["1"].single), the following happens:

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/neo4jrestclient/iterable.py in single(self)
     65     def single(self):
     66         try:
---> 67             return self[0]
     68         except KeyError:
     69             return None

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/neo4jrestclient/iterable.py in __getitem__(self, index)
     29 
     30     def __getitem__(self, index):
---> 31         elto = super(Iterable, self).__getitem__(index)
     32         if self._attribute:
     33             return self._class(elto[self._attribute], update_dict=elto,

IndexError: list index out of range

We can see the code here:

https://github.com/versae/neo4j-rest-client/blob/master/neo4jrestclient/iterable.py#L68

I think what is meant is catching an IndexError rather than KeyError. Could that be the case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions