Skip to content

Commit

Permalink
fix: validate index type on find_in_box
Browse files Browse the repository at this point in the history
  • Loading branch information
aMahanna committed Aug 18, 2023
1 parent 0b576c6 commit 58a6711
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,9 @@ def find_in_box(
geo_index = self.get_index(f"{self.name}/{index}")
assert isinstance(geo_index, dict)

if geo_index["type"] != "geo":
raise ValueError("**index** must point to a Geo Index")

geo_index_fields = geo_index["fields"]

if len(geo_index_fields) == 1:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,27 @@ def test_document_find_in_box(col, bad_col, geo, cluster):
)
assert clean_doc(result) in [[doc1], [doc2], [doc3], [doc4]]

# Test find_in_box with non-existing index
with assert_raises(IndexGetError) as err:
col.find_in_box(
latitude1=0,
longitude1=0,
latitude2=6,
longitude2=3,
index='abc',
)

# Test find_in_box with non-geo index
non_geo = col.add_hash_index(fields=['loc'])
with assert_raises(ValueError) as err:
col.find_in_box(
latitude1=0,
longitude1=0,
latitude2=6,
longitude2=3,
index=non_geo["id"],
)

# Test find_in_box with bad collection
with assert_raises(IndexGetError) as err:
bad_col.find_in_box(
Expand Down

0 comments on commit 58a6711

Please sign in to comment.