-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix node deletion with unidirectional optional relationship
- Loading branch information
Showing
5 changed files
with
168 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from infrahub.core.query.relationship import RelationshipGetPeerQuery | ||
from infrahub.core.relationship import Relationship | ||
from infrahub.core.schema import RelationshipSchema | ||
from infrahub.core.timestamp import Timestamp | ||
from infrahub.database import InfrahubDatabase | ||
|
||
|
||
async def query_peers_relationships( # type: ignore[no-untyped-def] | ||
db: InfrahubDatabase, | ||
source_ids: list[str], | ||
source_kind: str, | ||
rel_schema: RelationshipSchema, | ||
filters: dict, | ||
at: Timestamp, | ||
branch, # from infrahub.core.branch import Branch leads to circular import and cannot be used within TYPE_CHECKING block. Why? | ||
branch_agnostic: bool = False, | ||
offset: int | None = None, | ||
limit: int | None = None, | ||
) -> list[Relationship]: | ||
rel = Relationship(schema=rel_schema, branch=branch, node_id="PLACEHOLDER") | ||
|
||
query = await RelationshipGetPeerQuery.init( | ||
db=db, | ||
source_ids=source_ids, | ||
source_kind=source_kind, | ||
schema=rel_schema, | ||
filters=filters, | ||
rel=rel, | ||
offset=offset, | ||
limit=limit, | ||
at=at, | ||
branch_agnostic=branch_agnostic, | ||
) | ||
await query.execute(db=db) | ||
|
||
rels = [ | ||
await Relationship(schema=rel_schema, branch=branch, at=at, node_id=str(peer.source_id)).load( | ||
db=db, | ||
id=peer.rel_node_id, | ||
db_id=peer.rel_node_db_id, | ||
updated_at=peer.updated_at, | ||
data=peer, | ||
) | ||
for peer in query.get_peers() | ||
] | ||
return rels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters