Skip to content

Commit

Permalink
Fix index out of range for drift detection returning no results (#1220)
Browse files Browse the repository at this point in the history
It's possible for neo4j sessions `read_transaction` in `get_state` to
return an empty list in the drift detection module.

This PR ensures that there are entries before referencing index 0.
```
File "/code/venvs/venv/lib/python3.8/site-packages/cartography/driftdetect/get_states.py", line 123, in get_query_state
    get_state(session, state)
  File "/code/venvs/venv/lib/python3.8/site-packages/cartography/driftdetect/get_states.py", line 148, in get_state
    state.properties = list(new_results[0].keys())
IndexError: list index out of range
```
  • Loading branch information
skiptomyliu authored Jul 17, 2023
1 parent fb3247a commit ff94338
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cartography/driftdetect/get_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def get_state(session: neo4j.Session, state: State) -> None:
logger.debug(f"Updating results for {state.name}")

# The keys will be the same across all items in the returned list
state.properties = list(new_results[0].keys())
results = []
state.properties = list(new_results[0].keys()) if len(new_results) > 0 else []

results = []
for record in new_results:
values = []
for field in record.values():
Expand Down

0 comments on commit ff94338

Please sign in to comment.