Skip to content

Commit

Permalink
[core][fix] Only combine terms for properties in the reported section (
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Jun 5, 2024
1 parent b825649 commit e93cd56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions fixcore/fixcore/db/arango_query_rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion fixcore/tests/fixcore/db/arango_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e93cd56

Please sign in to comment.