infrahub-server 1.2.9rc0__py3-none-any.whl → 1.3.0a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. infrahub/actions/constants.py +86 -0
  2. infrahub/actions/gather.py +114 -0
  3. infrahub/actions/models.py +241 -0
  4. infrahub/actions/parsers.py +104 -0
  5. infrahub/actions/schema.py +382 -0
  6. infrahub/actions/tasks.py +126 -0
  7. infrahub/actions/triggers.py +21 -0
  8. infrahub/cli/db.py +1 -2
  9. infrahub/computed_attribute/models.py +13 -0
  10. infrahub/computed_attribute/tasks.py +48 -26
  11. infrahub/config.py +9 -0
  12. infrahub/core/account.py +24 -47
  13. infrahub/core/attribute.py +53 -14
  14. infrahub/core/branch/models.py +8 -9
  15. infrahub/core/branch/tasks.py +0 -2
  16. infrahub/core/constants/infrahubkind.py +8 -0
  17. infrahub/core/constraint/node/runner.py +1 -1
  18. infrahub/core/convert_object_type/__init__.py +0 -0
  19. infrahub/core/convert_object_type/conversion.py +122 -0
  20. infrahub/core/convert_object_type/schema_mapping.py +56 -0
  21. infrahub/core/diff/calculator.py +65 -11
  22. infrahub/core/diff/combiner.py +38 -31
  23. infrahub/core/diff/coordinator.py +44 -28
  24. infrahub/core/diff/data_check_synchronizer.py +3 -2
  25. infrahub/core/diff/enricher/hierarchy.py +36 -27
  26. infrahub/core/diff/ipam_diff_parser.py +5 -4
  27. infrahub/core/diff/merger/merger.py +46 -16
  28. infrahub/core/diff/merger/serializer.py +1 -0
  29. infrahub/core/diff/model/field_specifiers_map.py +64 -0
  30. infrahub/core/diff/model/path.py +58 -58
  31. infrahub/core/diff/parent_node_adder.py +14 -16
  32. infrahub/core/diff/query/all_conflicts.py +1 -5
  33. infrahub/core/diff/query/artifact.py +10 -20
  34. infrahub/core/diff/query/diff_get.py +3 -6
  35. infrahub/core/diff/query/drop_nodes.py +42 -0
  36. infrahub/core/diff/query/field_specifiers.py +8 -7
  37. infrahub/core/diff/query/field_summary.py +2 -4
  38. infrahub/core/diff/query/filters.py +15 -1
  39. infrahub/core/diff/query/merge.py +284 -101
  40. infrahub/core/diff/query/save.py +26 -34
  41. infrahub/core/diff/query/summary_counts_enricher.py +34 -54
  42. infrahub/core/diff/query_parser.py +55 -65
  43. infrahub/core/diff/repository/deserializer.py +38 -24
  44. infrahub/core/diff/repository/repository.py +31 -12
  45. infrahub/core/diff/tasks.py +3 -3
  46. infrahub/core/graph/__init__.py +1 -1
  47. infrahub/core/manager.py +14 -11
  48. infrahub/core/migrations/graph/__init__.py +2 -0
  49. infrahub/core/migrations/graph/m003_relationship_parent_optional.py +1 -2
  50. infrahub/core/migrations/graph/m013_convert_git_password_credential.py +2 -4
  51. infrahub/core/migrations/graph/m019_restore_rels_to_time.py +11 -22
  52. infrahub/core/migrations/graph/m020_duplicate_edges.py +3 -6
  53. infrahub/core/migrations/graph/m021_missing_hierarchy_merge.py +1 -2
  54. infrahub/core/migrations/graph/m024_missing_hierarchy_backfill.py +1 -2
  55. infrahub/core/migrations/graph/m027_delete_isolated_nodes.py +50 -0
  56. infrahub/core/migrations/graph/m028_delete_diffs.py +38 -0
  57. infrahub/core/migrations/query/attribute_add.py +1 -2
  58. infrahub/core/migrations/query/attribute_rename.py +3 -6
  59. infrahub/core/migrations/query/delete_element_in_schema.py +3 -6
  60. infrahub/core/migrations/query/node_duplicate.py +3 -6
  61. infrahub/core/migrations/query/relationship_duplicate.py +3 -6
  62. infrahub/core/migrations/schema/node_attribute_remove.py +3 -6
  63. infrahub/core/migrations/schema/node_remove.py +3 -6
  64. infrahub/core/models.py +29 -2
  65. infrahub/core/node/__init__.py +18 -4
  66. infrahub/core/node/create.py +211 -0
  67. infrahub/core/protocols.py +51 -0
  68. infrahub/core/protocols_base.py +3 -0
  69. infrahub/core/query/__init__.py +2 -2
  70. infrahub/core/query/branch.py +27 -17
  71. infrahub/core/query/diff.py +186 -81
  72. infrahub/core/query/ipam.py +10 -20
  73. infrahub/core/query/node.py +65 -49
  74. infrahub/core/query/relationship.py +156 -58
  75. infrahub/core/query/resource_manager.py +1 -2
  76. infrahub/core/query/subquery.py +4 -6
  77. infrahub/core/relationship/model.py +4 -1
  78. infrahub/core/schema/__init__.py +2 -1
  79. infrahub/core/schema/attribute_parameters.py +36 -0
  80. infrahub/core/schema/attribute_schema.py +83 -8
  81. infrahub/core/schema/basenode_schema.py +25 -1
  82. infrahub/core/schema/definitions/core/__init__.py +21 -0
  83. infrahub/core/schema/definitions/internal.py +13 -3
  84. infrahub/core/schema/generated/attribute_schema.py +9 -3
  85. infrahub/core/schema/schema_branch.py +15 -7
  86. infrahub/core/validators/__init__.py +5 -1
  87. infrahub/core/validators/attribute/choices.py +1 -2
  88. infrahub/core/validators/attribute/enum.py +1 -2
  89. infrahub/core/validators/attribute/kind.py +1 -2
  90. infrahub/core/validators/attribute/length.py +13 -6
  91. infrahub/core/validators/attribute/optional.py +1 -2
  92. infrahub/core/validators/attribute/regex.py +5 -5
  93. infrahub/core/validators/attribute/unique.py +1 -3
  94. infrahub/core/validators/determiner.py +18 -2
  95. infrahub/core/validators/enum.py +7 -0
  96. infrahub/core/validators/node/hierarchy.py +3 -6
  97. infrahub/core/validators/query.py +1 -3
  98. infrahub/core/validators/relationship/count.py +6 -12
  99. infrahub/core/validators/relationship/optional.py +2 -4
  100. infrahub/core/validators/relationship/peer.py +3 -8
  101. infrahub/core/validators/tasks.py +1 -1
  102. infrahub/core/validators/uniqueness/query.py +12 -9
  103. infrahub/database/__init__.py +1 -3
  104. infrahub/events/group_action.py +1 -0
  105. infrahub/graphql/analyzer.py +139 -18
  106. infrahub/graphql/app.py +1 -1
  107. infrahub/graphql/loaders/node.py +1 -1
  108. infrahub/graphql/loaders/peers.py +1 -1
  109. infrahub/graphql/manager.py +4 -0
  110. infrahub/graphql/mutations/action.py +164 -0
  111. infrahub/graphql/mutations/convert_object_type.py +62 -0
  112. infrahub/graphql/mutations/main.py +24 -175
  113. infrahub/graphql/mutations/proposed_change.py +21 -18
  114. infrahub/graphql/queries/convert_object_type_mapping.py +36 -0
  115. infrahub/graphql/queries/diff/tree.py +2 -1
  116. infrahub/graphql/queries/relationship.py +1 -1
  117. infrahub/graphql/resolvers/many_relationship.py +4 -4
  118. infrahub/graphql/resolvers/resolver.py +4 -4
  119. infrahub/graphql/resolvers/single_relationship.py +2 -2
  120. infrahub/graphql/schema.py +6 -0
  121. infrahub/graphql/subscription/graphql_query.py +2 -2
  122. infrahub/graphql/types/branch.py +1 -1
  123. infrahub/menu/menu.py +31 -0
  124. infrahub/message_bus/messages/__init__.py +0 -10
  125. infrahub/message_bus/operations/__init__.py +0 -8
  126. infrahub/message_bus/operations/refresh/registry.py +1 -1
  127. infrahub/patch/queries/consolidate_duplicated_nodes.py +3 -6
  128. infrahub/patch/queries/delete_duplicated_edges.py +5 -10
  129. infrahub/prefect_server/models.py +1 -19
  130. infrahub/proposed_change/models.py +68 -3
  131. infrahub/proposed_change/tasks.py +907 -30
  132. infrahub/task_manager/models.py +10 -6
  133. infrahub/telemetry/database.py +1 -1
  134. infrahub/telemetry/tasks.py +1 -1
  135. infrahub/trigger/catalogue.py +2 -0
  136. infrahub/trigger/models.py +29 -3
  137. infrahub/trigger/setup.py +51 -15
  138. infrahub/trigger/tasks.py +4 -5
  139. infrahub/types.py +1 -1
  140. infrahub/webhook/models.py +2 -1
  141. infrahub/workflows/catalogue.py +85 -0
  142. infrahub/workflows/initialization.py +1 -3
  143. infrahub_sdk/timestamp.py +2 -2
  144. {infrahub_server-1.2.9rc0.dist-info → infrahub_server-1.3.0a0.dist-info}/METADATA +4 -4
  145. {infrahub_server-1.2.9rc0.dist-info → infrahub_server-1.3.0a0.dist-info}/RECORD +153 -146
  146. infrahub_testcontainers/container.py +0 -1
  147. infrahub_testcontainers/docker-compose.test.yml +4 -4
  148. infrahub_testcontainers/helpers.py +8 -2
  149. infrahub_testcontainers/performance_test.py +6 -3
  150. infrahub/message_bus/messages/check_generator_run.py +0 -26
  151. infrahub/message_bus/messages/finalize_validator_execution.py +0 -15
  152. infrahub/message_bus/messages/proposed_change/base_with_diff.py +0 -16
  153. infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +0 -11
  154. infrahub/message_bus/messages/request_generatordefinition_check.py +0 -20
  155. infrahub/message_bus/messages/request_proposedchange_pipeline.py +0 -23
  156. infrahub/message_bus/operations/check/__init__.py +0 -3
  157. infrahub/message_bus/operations/check/generator.py +0 -156
  158. infrahub/message_bus/operations/finalize/__init__.py +0 -3
  159. infrahub/message_bus/operations/finalize/validator.py +0 -133
  160. infrahub/message_bus/operations/requests/__init__.py +0 -9
  161. infrahub/message_bus/operations/requests/generator_definition.py +0 -140
  162. infrahub/message_bus/operations/requests/proposed_change.py +0 -629
  163. /infrahub/{message_bus/messages/proposed_change → actions}/__init__.py +0 -0
  164. {infrahub_server-1.2.9rc0.dist-info → infrahub_server-1.3.0a0.dist-info}/LICENSE.txt +0 -0
  165. {infrahub_server-1.2.9rc0.dist-info → infrahub_server-1.3.0a0.dist-info}/WHEEL +0 -0
  166. {infrahub_server-1.2.9rc0.dist-info → infrahub_server-1.3.0a0.dist-info}/entry_points.txt +0 -0
@@ -92,6 +92,7 @@ class NodeAttributesFromDB:
92
92
  class PeerInfo:
93
93
  uuid: str
94
94
  kind: str
95
+ db_id: str
95
96
 
96
97
 
97
98
  class NodeQuery(Query):
@@ -206,12 +207,11 @@ class NodeCreateAllQuery(NodeQuery):
206
207
  attrs_query = """
207
208
  WITH distinct n
208
209
  UNWIND $attrs AS attr
209
- CALL {
210
- WITH n, attr
210
+ CALL (n, attr) {
211
211
  CREATE (a:Attribute { uuid: attr.uuid, name: attr.name, branch_support: attr.branch_support })
212
212
  CREATE (n)-[:HAS_ATTRIBUTE { branch: attr.branch, branch_level: attr.branch_level, status: attr.status, from: $at }]->(a)
213
213
  MERGE (av:AttributeValue { value: attr.content.value, is_default: attr.content.is_default })
214
- WITH n, attr, av, a
214
+ WITH av, a
215
215
  LIMIT 1
216
216
  CREATE (a)-[:HAS_VALUE { branch: attr.branch, branch_level: attr.branch_level, status: attr.status, from: $at }]->(av)
217
217
  MERGE (ip:Boolean { value: attr.is_protected })
@@ -231,13 +231,12 @@ class NodeCreateAllQuery(NodeQuery):
231
231
  attrs_iphost_query = """
232
232
  WITH distinct n
233
233
  UNWIND $attrs_iphost AS attr_iphost
234
- CALL {
235
- WITH n, attr_iphost
234
+ CALL (n, attr_iphost) {
236
235
  WITH n, attr_iphost AS attr
237
236
  CREATE (a:Attribute { uuid: attr.uuid, name: attr.name, branch_support: attr.branch_support })
238
237
  CREATE (n)-[:HAS_ATTRIBUTE { branch: attr.branch, branch_level: attr.branch_level, status: attr.status, from: $at }]->(a)
239
238
  MERGE (av:AttributeValue:AttributeIPHost { %(iphost_prop)s })
240
- WITH n, attr, av, a
239
+ WITH attr, av, a
241
240
  LIMIT 1
242
241
  CREATE (a)-[:HAS_VALUE { branch: attr.branch, branch_level: attr.branch_level, status: attr.status, from: $at }]->(av)
243
242
  MERGE (ip:Boolean { value: attr.is_protected })
@@ -258,13 +257,12 @@ class NodeCreateAllQuery(NodeQuery):
258
257
  attrs_ipnetwork_query = """
259
258
  WITH distinct n
260
259
  UNWIND $attrs_ipnetwork AS attr_ipnetwork
261
- CALL {
262
- WITH n, attr_ipnetwork
260
+ CALL (n, attr_ipnetwork) {
263
261
  WITH n, attr_ipnetwork AS attr
264
262
  CREATE (a:Attribute { uuid: attr.uuid, name: attr.name, branch_support: attr.branch_support })
265
263
  CREATE (n)-[:HAS_ATTRIBUTE { branch: attr.branch, branch_level: attr.branch_level, status: attr.status, from: $at }]->(a)
266
264
  MERGE (av:AttributeValue:AttributeIPNetwork { %(ipnetwork_prop)s })
267
- WITH n, attr, av, a
265
+ WITH attr, av, a
268
266
  LIMIT 1
269
267
  CREATE (a)-[:HAS_VALUE { branch: attr.branch, branch_level: attr.branch_level, status: attr.status, from: $at }]->(av)
270
268
  MERGE (ip:Boolean { value: attr.is_protected })
@@ -285,8 +283,7 @@ class NodeCreateAllQuery(NodeQuery):
285
283
  rels_bidir_query = """
286
284
  WITH distinct n
287
285
  UNWIND $rels_bidir AS rel
288
- CALL {
289
- WITH n, rel
286
+ CALL (n, rel) {
290
287
  MERGE (d:Node { uuid: rel.destination_id })
291
288
  CREATE (rl:Relationship { uuid: rel.uuid, name: rel.name, branch_support: rel.branch_support })
292
289
  CREATE (n)-[:IS_RELATED %(rel_prop)s ]->(rl)
@@ -309,8 +306,7 @@ class NodeCreateAllQuery(NodeQuery):
309
306
  rels_out_query = """
310
307
  WITH distinct n
311
308
  UNWIND $rels_out AS rel_out
312
- CALL {
313
- WITH n, rel_out
309
+ CALL (n, rel_out) {
314
310
  WITH n, rel_out as rel
315
311
  MERGE (d:Node { uuid: rel.destination_id })
316
312
  CREATE (rl:Relationship { uuid: rel.uuid, name: rel.name, branch_support: rel.branch_support })
@@ -334,8 +330,7 @@ class NodeCreateAllQuery(NodeQuery):
334
330
  rels_in_query = """
335
331
  WITH distinct n
336
332
  UNWIND $rels_in AS rel_in
337
- CALL {
338
- WITH n, rel_in
333
+ CALL (n, rel_in) {
339
334
  WITH n, rel_in AS rel
340
335
  MERGE (d:Node { uuid: rel.destination_id })
341
336
  CREATE (rl:Relationship { uuid: rel.uuid, name: rel.name, branch_support: rel.branch_support })
@@ -412,9 +407,31 @@ class NodeDeleteQuery(NodeQuery):
412
407
  self.params["branch"] = self.branch.name
413
408
  self.params["branch_level"] = self.branch.hierarchy_level
414
409
 
410
+ if self.branch.is_global or self.branch.is_default:
411
+ node_query_match = """
412
+ MATCH (n:Node { uuid: $uuid })
413
+ OPTIONAL MATCH (n)-[delete_edge:IS_PART_OF {status: "deleted", branch: $branch}]->(:Root)
414
+ WHERE delete_edge.from <= $at
415
+ WITH n WHERE delete_edge IS NULL
416
+ """
417
+ else:
418
+ node_filter, node_filter_params = self.branch.get_query_filter_path(at=self.at, variable_name="r")
419
+ node_query_match = """
420
+ MATCH (n:Node { uuid: $uuid })
421
+ CALL (n) {
422
+ MATCH (n)-[r:IS_PART_OF]->(:Root)
423
+ WHERE %(node_filter)s
424
+ RETURN r.status = "active" AS is_active
425
+ ORDER BY r.from DESC
426
+ LIMIT 1
427
+ }
428
+ WITH n WHERE is_active = TRUE
429
+ """ % {"node_filter": node_filter}
430
+ self.params.update(node_filter_params)
431
+ self.add_to_query(node_query_match)
432
+
415
433
  query = """
416
434
  MATCH (root:Root)
417
- MATCH (n:Node { uuid: $uuid })
418
435
  CREATE (n)-[r:IS_PART_OF { branch: $branch, branch_level: $branch_level, status: "deleted", from: $at }]->(root)
419
436
  """
420
437
 
@@ -496,8 +513,7 @@ class NodeListGetAttributeQuery(Query):
496
513
  self.add_to_query(query)
497
514
 
498
515
  query = """
499
- CALL {
500
- WITH n, a
516
+ CALL (n, a) {
501
517
  MATCH (n)-[r:HAS_ATTRIBUTE]-(a:Attribute)
502
518
  WHERE %(branch_filter)s
503
519
  RETURN n as n1, r as r1, a as a1
@@ -509,8 +525,7 @@ class NodeListGetAttributeQuery(Query):
509
525
  WITH n, r1, a
510
526
  MATCH (a)-[r:HAS_VALUE]-(av:AttributeValue)
511
527
  WHERE %(branch_filter)s
512
- CALL {
513
- WITH a, av
528
+ CALL (a, av) {
514
529
  MATCH (a)-[r:HAS_VALUE]-(av:AttributeValue)
515
530
  WHERE %(branch_filter)s
516
531
  RETURN a as a1, r as r2, av as av1
@@ -674,14 +689,12 @@ class NodeListGetRelationshipsQuery(Query):
674
689
 
675
690
  query = """
676
691
  MATCH (n:Node) WHERE n.uuid IN $ids
677
- CALL {
678
- WITH n
692
+ CALL (n) {
679
693
  MATCH (n)<-[:IS_RELATED]-(rel:Relationship)<-[:IS_RELATED]-(peer)
680
694
  WHERE ($inbound_identifiers IS NULL OR rel.name in $inbound_identifiers)
681
695
  AND n.uuid <> peer.uuid
682
696
  WITH DISTINCT n, rel, peer
683
- CALL {
684
- WITH n, rel, peer
697
+ CALL (n, rel, peer) {
685
698
  MATCH (n)<-[r:IS_RELATED]-(rel)
686
699
  WHERE (%(filters)s)
687
700
  WITH n, rel, peer, r
@@ -705,8 +718,7 @@ class NodeListGetRelationshipsQuery(Query):
705
718
  WHERE ($outbound_identifiers IS NULL OR rel.name in $outbound_identifiers)
706
719
  AND n.uuid <> peer.uuid
707
720
  WITH DISTINCT n, rel, peer
708
- CALL {
709
- WITH n, rel, peer
721
+ CALL (n, rel, peer) {
710
722
  MATCH (n)-[r:IS_RELATED]->(rel)
711
723
  WHERE (%(filters)s)
712
724
  WITH n, rel, peer, r
@@ -730,8 +742,7 @@ class NodeListGetRelationshipsQuery(Query):
730
742
  WHERE ($bidirectional_identifiers IS NULL OR rel.name in $bidirectional_identifiers)
731
743
  AND n.uuid <> peer.uuid
732
744
  WITH DISTINCT n, rel, peer
733
- CALL {
734
- WITH n, rel, peer
745
+ CALL (n, rel, peer) {
735
746
  MATCH (n)-[r:IS_RELATED]->(rel)
736
747
  WHERE (%(filters)s)
737
748
  WITH n, rel, peer, r
@@ -825,8 +836,7 @@ class NodeListGetInfoQuery(Query):
825
836
  query = """
826
837
  MATCH p = (root:Root)<-[:IS_PART_OF]-(n:Node)
827
838
  WHERE n.uuid IN $ids
828
- CALL {
829
- WITH root, n
839
+ CALL (root, n) {
830
840
  MATCH (root:Root)<-[r:IS_PART_OF]-(n:Node)
831
841
  WHERE %(branch_filter)s
832
842
  RETURN n as n1, r as r1
@@ -1022,8 +1032,7 @@ class NodeGetListQuery(Query):
1022
1032
  if not self.branch.is_default:
1023
1033
  topquery = """
1024
1034
  MATCH (n:%(node_kind)s)
1025
- CALL {
1026
- WITH n
1035
+ CALL (n) {
1027
1036
  MATCH (root:Root)<-[r:IS_PART_OF]-(n)
1028
1037
  WHERE %(branch_filter)s
1029
1038
  RETURN r
@@ -1128,7 +1137,7 @@ class NodeGetListQuery(Query):
1128
1137
  )
1129
1138
 
1130
1139
  filter_params.update(subquery_params)
1131
- filter_query.append("CALL {")
1140
+ filter_query.append("CALL (n) {")
1132
1141
  filter_query.append(subquery)
1133
1142
  filter_query.append("}")
1134
1143
  filter_query.append(f"WITH {with_str}")
@@ -1177,7 +1186,7 @@ class NodeGetListQuery(Query):
1177
1186
  with_str = ", ".join(self._get_tracked_variables())
1178
1187
 
1179
1188
  sort_params.update(subquery_params)
1180
- sort_query.append("CALL {")
1189
+ sort_query.append("CALL (n) {")
1181
1190
  sort_query.append(subquery)
1182
1191
  sort_query.append("}")
1183
1192
  sort_query.append(f"WITH {with_str}")
@@ -1191,8 +1200,7 @@ class NodeGetListQuery(Query):
1191
1200
  froms_str = db.render_list_comprehension(items="relationships(profile_path)", item_name="from")
1192
1201
  profiles_per_node_query = (
1193
1202
  """
1194
- CALL {
1195
- WITH n
1203
+ CALL (n) {
1196
1204
  OPTIONAL MATCH profile_path = (n)-[:IS_RELATED]->(profile_r:Relationship)<-[:IS_RELATED]-(maybe_profile_n:Node)-[:IS_PART_OF]->(:Root)
1197
1205
  WHERE profile_r.name = "node__profile"
1198
1206
  AND all(r in relationships(profile_path) WHERE %(branch_filter)s)
@@ -1210,8 +1218,7 @@ class NodeGetListQuery(Query):
1210
1218
  WITH %(with_str)s, CASE
1211
1219
  WHEN ordered_is_actives[0] = True THEN maybe_profile_n ELSE NULL
1212
1220
  END AS profile_n
1213
- CALL {
1214
- WITH profile_n
1221
+ CALL (profile_n) {
1215
1222
  OPTIONAL MATCH profile_priority_path = (profile_n)-[pr1:HAS_ATTRIBUTE]->(a:Attribute)-[pr2:HAS_VALUE]->(av:AttributeValue)
1216
1223
  WHERE a.name = "profile_priority"
1217
1224
  AND all(r in relationships(profile_priority_path) WHERE %(branch_filter)s and r.status = "active")
@@ -1252,7 +1259,7 @@ class NodeGetListQuery(Query):
1252
1259
  self._track_variable(profile_attr.profile_value_query_variable)
1253
1260
  with_str = ", ".join(self._get_tracked_variables())
1254
1261
 
1255
- attributes_queries.append("CALL {")
1262
+ attributes_queries.append("CALL (profile_n) {")
1256
1263
  attributes_queries.append(subquery)
1257
1264
  attributes_queries.append("}")
1258
1265
  attributes_queries.append(f"WITH {with_str}")
@@ -1405,7 +1412,7 @@ class NodeGetHierarchyQuery(Query):
1405
1412
 
1406
1413
  super().__init__(**kwargs)
1407
1414
 
1408
- async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
1415
+ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002,PLR0915
1409
1416
  hierarchy_schema = self.node_schema.get_hierarchy_schema(db=db, branch=self.branch)
1410
1417
  branch_filter, branch_params = self.branch.get_query_filter_path(at=self.at.to_string())
1411
1418
  self.params.update(branch_params)
@@ -1433,13 +1440,16 @@ class NodeGetHierarchyQuery(Query):
1433
1440
  MATCH path = (n:Node { uuid: $uuid } )%(filter)s(peer:Node)
1434
1441
  WHERE $hierarchy IN LABELS(peer) and all(r IN relationships(path) WHERE (%(branch_filter)s))
1435
1442
  WITH n, collect(last(nodes(path))) AS peers_with_duplicates
1436
- CALL {
1437
- WITH peers_with_duplicates
1443
+ CALL (peers_with_duplicates) {
1438
1444
  UNWIND peers_with_duplicates AS pwd
1439
1445
  RETURN DISTINCT pwd AS peer
1440
1446
  }
1441
- CALL {
1442
- WITH n, peer
1447
+
1448
+ """ % {"filter": filter_str, "branch_filter": branch_filter}
1449
+
1450
+ if not self.branch.is_default:
1451
+ query += """
1452
+ CALL (n, peer) {
1443
1453
  MATCH path = (n)%(filter)s(peer)
1444
1454
  WHERE all(r IN relationships(path) WHERE (%(branch_filter)s))
1445
1455
  WITH %(with_clause)s
@@ -1448,10 +1458,14 @@ class NodeGetHierarchyQuery(Query):
1448
1458
  LIMIT 1
1449
1459
  }
1450
1460
  WITH peer1 as peer, is_active
1451
- """ % {"filter": filter_str, "branch_filter": branch_filter, "with_clause": with_clause}
1461
+ """ % {"filter": filter_str, "branch_filter": branch_filter, "with_clause": with_clause}
1462
+ else:
1463
+ query += """
1464
+ WITH peer
1465
+ """
1452
1466
 
1453
1467
  self.add_to_query(query)
1454
- where_clause = ["is_active = TRUE"]
1468
+ where_clause = ["is_active = TRUE"] if not self.branch.is_default else []
1455
1469
 
1456
1470
  clean_filters = extract_field_filters(field_name=self.direction.value, filters=self.filters)
1457
1471
 
@@ -1461,7 +1475,8 @@ class NodeGetHierarchyQuery(Query):
1461
1475
  if clean_filters.get("id", None):
1462
1476
  self.params["peer_ids"].append(clean_filters.get("id"))
1463
1477
 
1464
- self.add_to_query("WHERE " + " AND ".join(where_clause))
1478
+ if where_clause:
1479
+ self.add_to_query("WHERE " + " AND ".join(where_clause))
1465
1480
 
1466
1481
  self.return_labels = ["peer"]
1467
1482
 
@@ -1499,7 +1514,7 @@ class NodeGetHierarchyQuery(Query):
1499
1514
  [f"{subquery_result_name} as {label}" if label == "peer" else label for label in self.return_labels]
1500
1515
  )
1501
1516
 
1502
- self.add_subquery(subquery=subquery, with_clause=with_str)
1517
+ self.add_subquery(subquery=subquery, node_alias="peer", with_clause=with_str)
1503
1518
 
1504
1519
  # ----------------------------------------------------------------------------
1505
1520
  # ORDER Results
@@ -1527,7 +1542,7 @@ class NodeGetHierarchyQuery(Query):
1527
1542
  self.order_by.append(subquery_result_name)
1528
1543
  self.params.update(subquery_params)
1529
1544
 
1530
- self.add_subquery(subquery=subquery)
1545
+ self.add_subquery(subquery=subquery, node_alias="peer")
1531
1546
 
1532
1547
  order_cnt += 1
1533
1548
  else:
@@ -1544,4 +1559,5 @@ class NodeGetHierarchyQuery(Query):
1544
1559
  yield PeerInfo(
1545
1560
  uuid=peer_node.get("uuid"),
1546
1561
  kind=peer_node.get("kind"),
1562
+ db_id=peer_node.element_id,
1547
1563
  )