diff --git a/fixcore/fixcore/db/arango_query_rewrite.py b/fixcore/fixcore/db/arango_query_rewrite.py index 85480af256..02a40688f9 100644 --- a/fixcore/fixcore/db/arango_query_rewrite.py +++ b/fixcore/fixcore/db/arango_query_rewrite.py @@ -3,6 +3,7 @@ from attr import evolve from fixcore.db.model import QueryModel +from fixcore.model.graph_access import Section from fixcore.model.model import predefined_kinds_by_name from fixcore.query.model import ( Query, @@ -31,9 +32,11 @@ def no_context(term: Term) -> bool: def combine_term_if_possible(term: Term, predicates: List[Predicate]) -> Term: kinds = set() for pred in predicates: - for res in query_model.owners(pred.name): - if res.fqn not in predefined_kinds_by_name: - kinds.add(res.fqn) + # lookup kind by property path only makes sense in the reported section + if pred.name.startswith(Section.reported): + for res in query_model.owners(pred.name): + if res.fqn not in predefined_kinds_by_name: + kinds.add(res.fqn) kinds.discard("resource") # all resources have this base kind - ignore it return IsTerm(kinds=sorted(kinds)).and_term(term) if kinds else term diff --git a/fixcore/tests/fixcore/db/arango_query_test.py b/fixcore/tests/fixcore/db/arango_query_test.py index f3604449f4..51e990a88e 100644 --- a/fixcore/tests/fixcore/db/arango_query_test.py +++ b/fixcore/tests/fixcore/db/arango_query_test.py @@ -92,7 +92,7 @@ def query_string(query: str) -> str: def test_ancestors_kind_lookup(foo_model: Model, graph_db: GraphDB) -> None: # 1234 is coerced to a string _, bv = to_query(graph_db, QueryModel(parse_query("ancestors.account.reported.name==1234"), foo_model)) - assert bv["b7"] == "1234" + assert bv["b0"] == "1234" def test_escape_property_path(foo_model: Model, graph_db: GraphDB) -> None: