Issue
What is the issue?
get_cre_by_db_id() in application/database/db.py (line 1156) does:
return self.get_CREs(external_id=external_id[0])[0]
get_CREs() explicitly returns [] when no matching CRE is found (line 1276). Indexing into an empty list raises IndexError: list index out of range.
The function already handles the case where the CRE id is missing from the database (returning None), but not the case where the external_id exists in the CRE table but get_CREs finds nothing, which can happen under data inconsistency.
This function is called in __get_all_nodes_and_cres (iterates every CRE in the database) and get_path_between_cres. Both callers check if shallow_CRE expecting None, so they already handle None correctly but never receive it when get_CREs returns [].
Expected Behaviour
get_cre_by_db_id returns None and logs an error when get_CREs finds no results for the given external_id, consistent with its existing error handling.
Actual Behaviour
An unhandled IndexError is raised, which propagates as a 500 from any endpoint that triggers with_graph() or get_path_between_cres().
Steps to reproduce
Trigger any data inconsistency where a row exists in the CRE table but get_CREs() returns no results for its external_id, then call an endpoint that invokes __get_all_nodes_and_cres() or get_path_between_cres().
Issue
What is the issue?
get_cre_by_db_id()inapplication/database/db.py(line 1156) does:get_CREs()explicitly returns[]when no matching CRE is found (line 1276). Indexing into an empty list raisesIndexError: list index out of range.The function already handles the case where the CRE id is missing from the database (returning
None), but not the case where theexternal_idexists in theCREtable butget_CREsfinds nothing, which can happen under data inconsistency.This function is called in
__get_all_nodes_and_cres(iterates every CRE in the database) andget_path_between_cres. Both callers checkif shallow_CREexpectingNone, so they already handleNonecorrectly but never receive it whenget_CREsreturns[].Expected Behaviour
get_cre_by_db_idreturnsNoneand logs an error whenget_CREsfinds no results for the given external_id, consistent with its existing error handling.Actual Behaviour
An unhandled
IndexErroris raised, which propagates as a 500 from any endpoint that triggerswith_graph()orget_path_between_cres().Steps to reproduce
Trigger any data inconsistency where a row exists in the
CREtable butget_CREs()returns no results for itsexternal_id, then call an endpoint that invokes__get_all_nodes_and_cres()orget_path_between_cres().