Skip to content

Commit

Permalink
Keep subquery even if we are using filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarros committed Jan 6, 2025
1 parent 36b5367 commit ac2f6d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions backend/infrahub/core/query/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from infrahub import config
from infrahub.core.constants import (
AttributeDBNodeType,
BranchSupportType,
RelationshipDirection,
RelationshipHierarchyDirection,
)
Expand Down Expand Up @@ -868,7 +867,10 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
)
self.params.update(branch_params)

if (not self.branch.is_default and not self.has_filters) or self.schema.branch == BranchSupportType.AGNOSTIC:
# The initial subquery is used to filter out deleted nodes because we can have multiple valid results per branch
# and we need to filter out the one that have been deleted in the branch.
# If we are on the default branch, the subquery is not required because only one valid result is expected at a given time
if not self.branch.is_default:
topquery = """
MATCH (n:%(node_kind)s)
CALL {
Expand Down
5 changes: 4 additions & 1 deletion backend/tests/unit/core/test_node_get_list_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ async def test_query_NodeGetListQuery_filter_id(
async def test_query_NodeGetListQuery_filter_ids(
db: InfrahubDatabase, person_john_main, person_jim_main, person_albert_main, person_alfred_main, branch: Branch
):
node_to_delete = await NodeManager.get_one(id=person_jim_main.id, db=db, branch=branch)
await node_to_delete.delete(db=db)

person_schema = registry.schema.get(name="TestPerson", branch=branch)
person_schema.order_by = ["height__value"]
query = await NodeGetListQuery.init(
Expand All @@ -50,7 +53,7 @@ async def test_query_NodeGetListQuery_filter_ids(
filters={"ids": [person_jim_main.id, person_john_main.id, person_albert_main.id]},
)
await query.execute(db=db)
assert query.get_node_ids() == [person_albert_main.id, person_jim_main.id, person_john_main.id]
assert set(query.get_node_ids()) == {person_albert_main.id, person_john_main.id}


async def test_query_NodeGetListQuery_filter_attribute_isnull(
Expand Down

0 comments on commit ac2f6d9

Please sign in to comment.