infrahub-server 1.2.0rc0__py3-none-any.whl → 1.2.1__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 (365) hide show
  1. infrahub/api/dependencies.py +6 -6
  2. infrahub/api/diff/validation_models.py +7 -7
  3. infrahub/api/schema.py +1 -1
  4. infrahub/artifacts/models.py +5 -3
  5. infrahub/artifacts/tasks.py +3 -5
  6. infrahub/cli/__init__.py +13 -9
  7. infrahub/cli/constants.py +3 -0
  8. infrahub/cli/db.py +165 -183
  9. infrahub/cli/upgrade.py +146 -0
  10. infrahub/computed_attribute/gather.py +185 -0
  11. infrahub/computed_attribute/models.py +240 -12
  12. infrahub/computed_attribute/tasks.py +77 -441
  13. infrahub/computed_attribute/triggers.py +13 -47
  14. infrahub/config.py +43 -32
  15. infrahub/context.py +14 -0
  16. infrahub/core/account.py +4 -4
  17. infrahub/core/attribute.py +58 -58
  18. infrahub/core/branch/tasks.py +74 -22
  19. infrahub/core/changelog/diff.py +95 -36
  20. infrahub/core/changelog/models.py +217 -43
  21. infrahub/core/constants/__init__.py +28 -0
  22. infrahub/core/constants/infrahubkind.py +2 -0
  23. infrahub/core/constants/schema.py +2 -0
  24. infrahub/core/constraint/node/runner.py +9 -8
  25. infrahub/core/diff/branch_differ.py +10 -10
  26. infrahub/core/diff/enricher/cardinality_one.py +5 -0
  27. infrahub/core/diff/enricher/hierarchy.py +17 -4
  28. infrahub/core/diff/enricher/labels.py +5 -0
  29. infrahub/core/diff/enricher/path_identifier.py +4 -0
  30. infrahub/core/diff/ipam_diff_parser.py +4 -5
  31. infrahub/core/diff/model/diff.py +27 -27
  32. infrahub/core/diff/model/path.py +32 -9
  33. infrahub/core/diff/parent_node_adder.py +78 -0
  34. infrahub/core/diff/payload_builder.py +13 -2
  35. infrahub/core/diff/query/filters.py +2 -2
  36. infrahub/core/diff/query/merge.py +20 -17
  37. infrahub/core/diff/query/save.py +188 -182
  38. infrahub/core/diff/query/summary_counts_enricher.py +51 -4
  39. infrahub/core/diff/query_parser.py +4 -4
  40. infrahub/core/diff/repository/deserializer.py +8 -3
  41. infrahub/core/diff/repository/repository.py +156 -38
  42. infrahub/core/diff/tasks.py +4 -4
  43. infrahub/core/graph/__init__.py +1 -1
  44. infrahub/core/graph/index.py +3 -0
  45. infrahub/core/initialization.py +1 -10
  46. infrahub/core/ipam/constants.py +3 -4
  47. infrahub/core/ipam/reconciler.py +12 -12
  48. infrahub/core/ipam/utilization.py +10 -13
  49. infrahub/core/manager.py +36 -36
  50. infrahub/core/merge.py +7 -7
  51. infrahub/core/migrations/__init__.py +2 -3
  52. infrahub/core/migrations/graph/__init__.py +12 -3
  53. infrahub/core/migrations/graph/m017_add_core_profile.py +1 -5
  54. infrahub/core/migrations/graph/m018_uniqueness_nulls.py +4 -4
  55. infrahub/core/migrations/graph/m019_restore_rels_to_time.py +256 -0
  56. infrahub/core/migrations/graph/m020_duplicate_edges.py +160 -0
  57. infrahub/core/migrations/graph/m021_missing_hierarchy_merge.py +51 -0
  58. infrahub/core/migrations/graph/m022_add_generate_template_attr.py +48 -0
  59. infrahub/core/migrations/graph/m023_deduplicate_cardinality_one_relationships.py +96 -0
  60. infrahub/core/migrations/query/attribute_add.py +2 -2
  61. infrahub/core/migrations/query/node_duplicate.py +43 -26
  62. infrahub/core/migrations/query/schema_attribute_update.py +2 -2
  63. infrahub/core/migrations/schema/models.py +19 -4
  64. infrahub/core/migrations/schema/node_remove.py +26 -12
  65. infrahub/core/migrations/schema/tasks.py +2 -2
  66. infrahub/core/migrations/shared.py +16 -16
  67. infrahub/core/models.py +15 -6
  68. infrahub/core/node/__init__.py +43 -39
  69. infrahub/core/node/base.py +2 -4
  70. infrahub/core/node/constraints/attribute_uniqueness.py +2 -2
  71. infrahub/core/node/constraints/grouped_uniqueness.py +99 -47
  72. infrahub/core/node/constraints/interface.py +1 -2
  73. infrahub/core/node/delete_validator.py +3 -5
  74. infrahub/core/node/ipam.py +4 -4
  75. infrahub/core/node/permissions.py +7 -7
  76. infrahub/core/node/resource_manager/ip_address_pool.py +6 -6
  77. infrahub/core/node/resource_manager/ip_prefix_pool.py +6 -6
  78. infrahub/core/node/resource_manager/number_pool.py +3 -3
  79. infrahub/core/path.py +12 -12
  80. infrahub/core/property.py +11 -11
  81. infrahub/core/protocols.py +7 -0
  82. infrahub/core/protocols_base.py +21 -21
  83. infrahub/core/query/__init__.py +33 -33
  84. infrahub/core/query/attribute.py +6 -4
  85. infrahub/core/query/diff.py +3 -3
  86. infrahub/core/query/node.py +82 -32
  87. infrahub/core/query/relationship.py +228 -40
  88. infrahub/core/query/resource_manager.py +2 -0
  89. infrahub/core/query/standard_node.py +3 -3
  90. infrahub/core/query/subquery.py +9 -9
  91. infrahub/core/registry.py +13 -15
  92. infrahub/core/relationship/constraints/count.py +3 -4
  93. infrahub/core/relationship/constraints/peer_kind.py +3 -4
  94. infrahub/core/relationship/constraints/profiles_kind.py +2 -2
  95. infrahub/core/relationship/model.py +51 -59
  96. infrahub/core/schema/attribute_schema.py +16 -8
  97. infrahub/core/schema/basenode_schema.py +105 -44
  98. infrahub/core/schema/computed_attribute.py +3 -3
  99. infrahub/core/schema/definitions/core/__init__.py +147 -0
  100. infrahub/core/schema/definitions/core/account.py +171 -0
  101. infrahub/core/schema/definitions/core/artifact.py +136 -0
  102. infrahub/core/schema/definitions/core/builtin.py +24 -0
  103. infrahub/core/schema/definitions/core/check.py +68 -0
  104. infrahub/core/schema/definitions/core/core.py +17 -0
  105. infrahub/core/schema/definitions/core/generator.py +100 -0
  106. infrahub/core/schema/definitions/core/graphql_query.py +79 -0
  107. infrahub/core/schema/definitions/core/group.py +108 -0
  108. infrahub/core/schema/definitions/core/ipam.py +193 -0
  109. infrahub/core/schema/definitions/core/lineage.py +19 -0
  110. infrahub/core/schema/definitions/core/menu.py +48 -0
  111. infrahub/core/schema/definitions/core/permission.py +163 -0
  112. infrahub/core/schema/definitions/core/profile.py +18 -0
  113. infrahub/core/schema/definitions/core/propose_change.py +97 -0
  114. infrahub/core/schema/definitions/core/propose_change_comment.py +193 -0
  115. infrahub/core/schema/definitions/core/propose_change_validator.py +328 -0
  116. infrahub/core/schema/definitions/core/repository.py +286 -0
  117. infrahub/core/schema/definitions/core/resource_pool.py +170 -0
  118. infrahub/core/schema/definitions/core/template.py +27 -0
  119. infrahub/core/schema/definitions/core/transform.py +96 -0
  120. infrahub/core/schema/definitions/core/webhook.py +134 -0
  121. infrahub/core/schema/definitions/internal.py +16 -16
  122. infrahub/core/schema/dropdown.py +3 -4
  123. infrahub/core/schema/generated/attribute_schema.py +15 -18
  124. infrahub/core/schema/generated/base_node_schema.py +12 -14
  125. infrahub/core/schema/generated/node_schema.py +3 -5
  126. infrahub/core/schema/generated/relationship_schema.py +9 -11
  127. infrahub/core/schema/generic_schema.py +2 -2
  128. infrahub/core/schema/manager.py +20 -9
  129. infrahub/core/schema/node_schema.py +4 -2
  130. infrahub/core/schema/relationship_schema.py +14 -6
  131. infrahub/core/schema/schema_branch.py +292 -144
  132. infrahub/core/schema/schema_branch_computed.py +41 -4
  133. infrahub/core/task/task.py +3 -3
  134. infrahub/core/task/user_task.py +15 -15
  135. infrahub/core/timestamp.py +3 -3
  136. infrahub/core/utils.py +20 -18
  137. infrahub/core/validators/__init__.py +1 -3
  138. infrahub/core/validators/aggregated_checker.py +2 -2
  139. infrahub/core/validators/attribute/choices.py +2 -2
  140. infrahub/core/validators/attribute/enum.py +2 -2
  141. infrahub/core/validators/attribute/kind.py +2 -2
  142. infrahub/core/validators/attribute/length.py +2 -2
  143. infrahub/core/validators/attribute/optional.py +2 -2
  144. infrahub/core/validators/attribute/regex.py +2 -2
  145. infrahub/core/validators/attribute/unique.py +2 -2
  146. infrahub/core/validators/checks_runner.py +25 -2
  147. infrahub/core/validators/determiner.py +1 -3
  148. infrahub/core/validators/interface.py +6 -2
  149. infrahub/core/validators/model.py +22 -3
  150. infrahub/core/validators/models/validate_migration.py +17 -4
  151. infrahub/core/validators/node/attribute.py +2 -2
  152. infrahub/core/validators/node/generate_profile.py +2 -2
  153. infrahub/core/validators/node/hierarchy.py +3 -5
  154. infrahub/core/validators/node/inherit_from.py +27 -5
  155. infrahub/core/validators/node/relationship.py +2 -2
  156. infrahub/core/validators/relationship/count.py +4 -4
  157. infrahub/core/validators/relationship/optional.py +2 -2
  158. infrahub/core/validators/relationship/peer.py +2 -2
  159. infrahub/core/validators/shared.py +2 -2
  160. infrahub/core/validators/tasks.py +8 -0
  161. infrahub/core/validators/uniqueness/checker.py +22 -21
  162. infrahub/core/validators/uniqueness/index.py +2 -2
  163. infrahub/core/validators/uniqueness/model.py +11 -11
  164. infrahub/database/__init__.py +27 -22
  165. infrahub/database/metrics.py +7 -1
  166. infrahub/dependencies/builder/constraint/grouped/node_runner.py +1 -3
  167. infrahub/dependencies/builder/diff/deserializer.py +3 -1
  168. infrahub/dependencies/builder/diff/enricher/hierarchy.py +3 -1
  169. infrahub/dependencies/builder/diff/parent_node_adder.py +8 -0
  170. infrahub/dependencies/component/registry.py +2 -2
  171. infrahub/events/__init__.py +25 -2
  172. infrahub/events/artifact_action.py +64 -0
  173. infrahub/events/branch_action.py +33 -22
  174. infrahub/events/generator.py +71 -0
  175. infrahub/events/group_action.py +51 -21
  176. infrahub/events/models.py +18 -19
  177. infrahub/events/node_action.py +88 -37
  178. infrahub/events/repository_action.py +5 -18
  179. infrahub/events/schema_action.py +4 -9
  180. infrahub/events/utils.py +16 -0
  181. infrahub/events/validator_action.py +55 -0
  182. infrahub/exceptions.py +32 -24
  183. infrahub/generators/models.py +2 -3
  184. infrahub/generators/tasks.py +24 -4
  185. infrahub/git/base.py +7 -7
  186. infrahub/git/integrator.py +48 -24
  187. infrahub/git/models.py +101 -9
  188. infrahub/git/repository.py +3 -3
  189. infrahub/git/tasks.py +408 -6
  190. infrahub/git/utils.py +48 -0
  191. infrahub/git/worktree.py +1 -2
  192. infrahub/git_credential/askpass.py +1 -2
  193. infrahub/graphql/analyzer.py +12 -0
  194. infrahub/graphql/app.py +13 -15
  195. infrahub/graphql/context.py +39 -0
  196. infrahub/graphql/initialization.py +3 -0
  197. infrahub/graphql/loaders/node.py +2 -12
  198. infrahub/graphql/loaders/peers.py +77 -0
  199. infrahub/graphql/loaders/shared.py +13 -0
  200. infrahub/graphql/manager.py +17 -19
  201. infrahub/graphql/mutations/artifact_definition.py +5 -5
  202. infrahub/graphql/mutations/branch.py +26 -1
  203. infrahub/graphql/mutations/computed_attribute.py +9 -5
  204. infrahub/graphql/mutations/diff.py +23 -11
  205. infrahub/graphql/mutations/diff_conflict.py +5 -0
  206. infrahub/graphql/mutations/generator.py +83 -0
  207. infrahub/graphql/mutations/graphql_query.py +5 -5
  208. infrahub/graphql/mutations/ipam.py +54 -74
  209. infrahub/graphql/mutations/main.py +195 -132
  210. infrahub/graphql/mutations/menu.py +7 -7
  211. infrahub/graphql/mutations/models.py +2 -4
  212. infrahub/graphql/mutations/node_getter/by_default_filter.py +10 -10
  213. infrahub/graphql/mutations/node_getter/by_hfid.py +1 -3
  214. infrahub/graphql/mutations/node_getter/by_id.py +1 -3
  215. infrahub/graphql/mutations/node_getter/interface.py +1 -2
  216. infrahub/graphql/mutations/proposed_change.py +7 -7
  217. infrahub/graphql/mutations/relationship.py +93 -19
  218. infrahub/graphql/mutations/repository.py +8 -8
  219. infrahub/graphql/mutations/resource_manager.py +3 -3
  220. infrahub/graphql/mutations/schema.py +19 -4
  221. infrahub/graphql/mutations/webhook.py +137 -0
  222. infrahub/graphql/parser.py +4 -4
  223. infrahub/graphql/permissions.py +1 -10
  224. infrahub/graphql/queries/diff/tree.py +19 -14
  225. infrahub/graphql/queries/event.py +5 -2
  226. infrahub/graphql/queries/ipam.py +2 -2
  227. infrahub/graphql/queries/relationship.py +2 -2
  228. infrahub/graphql/queries/search.py +2 -2
  229. infrahub/graphql/resolvers/many_relationship.py +264 -0
  230. infrahub/graphql/resolvers/resolver.py +13 -110
  231. infrahub/graphql/schema.py +2 -0
  232. infrahub/graphql/subscription/graphql_query.py +2 -0
  233. infrahub/graphql/types/context.py +12 -0
  234. infrahub/graphql/types/event.py +84 -17
  235. infrahub/graphql/types/node.py +2 -2
  236. infrahub/graphql/utils.py +2 -2
  237. infrahub/groups/ancestors.py +29 -0
  238. infrahub/groups/parsers.py +107 -0
  239. infrahub/lock.py +20 -20
  240. infrahub/menu/constants.py +0 -1
  241. infrahub/menu/generator.py +9 -21
  242. infrahub/menu/menu.py +17 -38
  243. infrahub/menu/models.py +117 -16
  244. infrahub/menu/repository.py +111 -0
  245. infrahub/menu/utils.py +5 -8
  246. infrahub/message_bus/__init__.py +11 -13
  247. infrahub/message_bus/messages/__init__.py +1 -21
  248. infrahub/message_bus/messages/check_generator_run.py +3 -3
  249. infrahub/message_bus/messages/finalize_validator_execution.py +3 -0
  250. infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +6 -0
  251. infrahub/message_bus/messages/request_generatordefinition_check.py +2 -0
  252. infrahub/message_bus/messages/send_echo_request.py +1 -1
  253. infrahub/message_bus/operations/__init__.py +1 -10
  254. infrahub/message_bus/operations/check/__init__.py +2 -2
  255. infrahub/message_bus/operations/check/generator.py +1 -0
  256. infrahub/message_bus/operations/event/__init__.py +2 -2
  257. infrahub/message_bus/operations/event/worker.py +0 -3
  258. infrahub/message_bus/operations/finalize/validator.py +51 -1
  259. infrahub/message_bus/operations/requests/__init__.py +0 -2
  260. infrahub/message_bus/operations/requests/generator_definition.py +21 -23
  261. infrahub/message_bus/operations/requests/proposed_change.py +14 -10
  262. infrahub/permissions/globals.py +15 -0
  263. infrahub/pools/number.py +2 -4
  264. infrahub/proposed_change/models.py +3 -0
  265. infrahub/proposed_change/tasks.py +58 -45
  266. infrahub/pytest_plugin.py +13 -10
  267. infrahub/server.py +2 -3
  268. infrahub/services/__init__.py +2 -2
  269. infrahub/services/adapters/cache/__init__.py +4 -6
  270. infrahub/services/adapters/cache/nats.py +4 -5
  271. infrahub/services/adapters/cache/redis.py +3 -7
  272. infrahub/services/adapters/event/__init__.py +1 -1
  273. infrahub/services/adapters/message_bus/__init__.py +3 -3
  274. infrahub/services/adapters/message_bus/local.py +2 -2
  275. infrahub/services/adapters/message_bus/nats.py +4 -4
  276. infrahub/services/adapters/message_bus/rabbitmq.py +4 -4
  277. infrahub/services/adapters/workflow/local.py +2 -2
  278. infrahub/services/component.py +5 -5
  279. infrahub/services/protocols.py +7 -7
  280. infrahub/services/scheduler.py +1 -3
  281. infrahub/task_manager/event.py +102 -9
  282. infrahub/task_manager/models.py +27 -7
  283. infrahub/tasks/artifact.py +7 -6
  284. infrahub/telemetry/__init__.py +0 -0
  285. infrahub/telemetry/constants.py +9 -0
  286. infrahub/telemetry/database.py +86 -0
  287. infrahub/telemetry/models.py +65 -0
  288. infrahub/telemetry/task_manager.py +77 -0
  289. infrahub/{tasks/telemetry.py → telemetry/tasks.py} +49 -56
  290. infrahub/telemetry/utils.py +11 -0
  291. infrahub/trace.py +4 -4
  292. infrahub/transformations/tasks.py +2 -2
  293. infrahub/trigger/catalogue.py +4 -6
  294. infrahub/trigger/constants.py +0 -8
  295. infrahub/trigger/models.py +54 -5
  296. infrahub/trigger/setup.py +90 -0
  297. infrahub/trigger/tasks.py +35 -84
  298. infrahub/utils.py +11 -1
  299. infrahub/validators/__init__.py +0 -0
  300. infrahub/validators/events.py +42 -0
  301. infrahub/validators/tasks.py +41 -0
  302. infrahub/webhook/gather.py +17 -0
  303. infrahub/webhook/models.py +176 -44
  304. infrahub/webhook/tasks.py +154 -155
  305. infrahub/webhook/triggers.py +31 -7
  306. infrahub/workers/infrahub_async.py +2 -2
  307. infrahub/workers/utils.py +2 -2
  308. infrahub/workflows/catalogue.py +86 -35
  309. infrahub/workflows/initialization.py +8 -2
  310. infrahub/workflows/models.py +27 -1
  311. infrahub/workflows/utils.py +10 -1
  312. infrahub_sdk/client.py +35 -8
  313. infrahub_sdk/config.py +3 -0
  314. infrahub_sdk/context.py +13 -0
  315. infrahub_sdk/ctl/branch.py +3 -2
  316. infrahub_sdk/ctl/cli_commands.py +5 -1
  317. infrahub_sdk/ctl/utils.py +0 -16
  318. infrahub_sdk/exceptions.py +12 -0
  319. infrahub_sdk/generator.py +4 -1
  320. infrahub_sdk/graphql.py +45 -13
  321. infrahub_sdk/node.py +71 -22
  322. infrahub_sdk/protocols.py +21 -8
  323. infrahub_sdk/protocols_base.py +32 -11
  324. infrahub_sdk/query_groups.py +6 -35
  325. infrahub_sdk/schema/__init__.py +55 -26
  326. infrahub_sdk/schema/main.py +8 -0
  327. infrahub_sdk/task/__init__.py +11 -0
  328. infrahub_sdk/task/constants.py +3 -0
  329. infrahub_sdk/task/exceptions.py +25 -0
  330. infrahub_sdk/task/manager.py +551 -0
  331. infrahub_sdk/task/models.py +74 -0
  332. infrahub_sdk/testing/schemas/animal.py +9 -0
  333. infrahub_sdk/timestamp.py +142 -33
  334. infrahub_sdk/utils.py +29 -1
  335. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/METADATA +8 -6
  336. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/RECORD +349 -293
  337. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/entry_points.txt +1 -0
  338. infrahub_testcontainers/constants.py +2 -0
  339. infrahub_testcontainers/container.py +157 -12
  340. infrahub_testcontainers/docker-compose.test.yml +31 -6
  341. infrahub_testcontainers/helpers.py +18 -73
  342. infrahub_testcontainers/host.py +41 -0
  343. infrahub_testcontainers/measurements.py +93 -0
  344. infrahub_testcontainers/models.py +38 -0
  345. infrahub_testcontainers/performance_test.py +166 -0
  346. infrahub_testcontainers/plugin.py +136 -0
  347. infrahub_testcontainers/prometheus.yml +30 -0
  348. infrahub/core/schema/definitions/core.py +0 -2286
  349. infrahub/message_bus/messages/check_repository_checkdefinition.py +0 -20
  350. infrahub/message_bus/messages/check_repository_mergeconflicts.py +0 -16
  351. infrahub/message_bus/messages/check_repository_usercheck.py +0 -26
  352. infrahub/message_bus/messages/event_branch_create.py +0 -11
  353. infrahub/message_bus/messages/event_branch_delete.py +0 -11
  354. infrahub/message_bus/messages/event_branch_rebased.py +0 -9
  355. infrahub/message_bus/messages/event_node_mutated.py +0 -15
  356. infrahub/message_bus/messages/event_schema_update.py +0 -9
  357. infrahub/message_bus/messages/request_repository_checks.py +0 -12
  358. infrahub/message_bus/messages/request_repository_userchecks.py +0 -18
  359. infrahub/message_bus/operations/check/repository.py +0 -293
  360. infrahub/message_bus/operations/event/node.py +0 -20
  361. infrahub/message_bus/operations/event/schema.py +0 -17
  362. infrahub/message_bus/operations/requests/repository.py +0 -133
  363. infrahub/webhook/constants.py +0 -1
  364. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/LICENSE.txt +0 -0
  365. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/WHEEL +0 -0
@@ -1,51 +1,38 @@
1
1
  from __future__ import annotations
2
2
 
3
- from datetime import timedelta
4
- from typing import TYPE_CHECKING, Any
3
+ from typing import TYPE_CHECKING
5
4
 
6
- import ujson
7
5
  from infrahub_sdk.protocols import (
8
6
  CoreNode, # noqa: TC002
9
7
  CoreTransformPython,
10
8
  )
11
9
  from prefect import flow
12
- from prefect.automations import AutomationCore
13
10
  from prefect.client.orchestration import get_client
14
- from prefect.client.schemas.filters import DeploymentFilter, DeploymentFilterName
15
- from prefect.events.actions import (
16
- RunDeployment,
17
- )
18
- from prefect.events.schemas.automations import EventTrigger, Posture
19
- from prefect.events.schemas.events import ResourceSpecification
20
11
  from prefect.logging import get_run_logger
21
12
 
22
13
  from infrahub.context import InfrahubContext # noqa: TC001 needed for prefect flow
23
14
  from infrahub.core.constants import ComputedAttributeKind, InfrahubKind
24
15
  from infrahub.core.registry import registry
16
+ from infrahub.events import BranchDeletedEvent
25
17
  from infrahub.git.repository import get_initialized_repo
26
18
  from infrahub.services import InfrahubServices # noqa: TC001 needed for prefect flow
27
19
  from infrahub.support.macro import MacroDefinition
20
+ from infrahub.trigger.models import TriggerType
21
+ from infrahub.trigger.setup import setup_triggers
28
22
  from infrahub.workflows.catalogue import (
29
- PROCESS_COMPUTED_MACRO,
30
- QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS,
23
+ COMPUTED_ATTRIBUTE_PROCESS_JINJA2,
24
+ COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
31
25
  TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
32
26
  TRIGGER_UPDATE_PYTHON_COMPUTED_ATTRIBUTES,
33
- UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM,
34
27
  )
35
28
  from infrahub.workflows.utils import add_tags, wait_for_schema_to_converge
36
29
 
37
- from .constants import (
38
- PROCESS_AUTOMATION_NAME,
39
- PROCESS_JINJA2_AUTOMATION_NAME_PREFIX,
40
- PROCESS_PYTHON_AUTOMATION_NAME_PREFIX,
41
- QUERY_AUTOMATION_NAME,
42
- QUERY_AUTOMATION_NAME_PREFIX,
30
+ from .gather import gather_trigger_computed_attribute_jinja2, gather_trigger_computed_attribute_python
31
+ from .models import (
32
+ PythonTransformTarget,
43
33
  )
44
- from .models import ComputedAttributeAutomations, PythonTransformComputedAttribute, PythonTransformTarget
45
34
 
46
35
  if TYPE_CHECKING:
47
- import logging
48
-
49
36
  from infrahub.core.schema.computed_attribute import ComputedAttribute
50
37
 
51
38
  UPDATE_ATTRIBUTE = """
@@ -65,7 +52,7 @@ mutation UpdateAttribute(
65
52
 
66
53
 
67
54
  @flow(
68
- name="process_computed_attribute_transform",
55
+ name="computed_attribute_process_transform",
69
56
  flow_run_name="Process computed attribute for {computed_attribute_kind}.{computed_attribute_name}",
70
57
  )
71
58
  async def process_transform(
@@ -115,7 +102,7 @@ async def process_transform(
115
102
  service=service,
116
103
  repository_kind=str(transform.repository.peer.typename),
117
104
  commit=repo_node.commit.value,
118
- )
105
+ ) # type: ignore[misc]
119
106
 
120
107
  data = await service.client.query_gql_query(
121
108
  name=transform.query.peer.name.value,
@@ -131,7 +118,7 @@ async def process_transform(
131
118
  location=f"{transform.file_path.value}::{transform.class_name.value}",
132
119
  data=data,
133
120
  client=service.client,
134
- )
121
+ ) # type: ignore[misc]
135
122
 
136
123
  await service.client.execute_graphql(
137
124
  query=UPDATE_ATTRIBUTE,
@@ -162,7 +149,7 @@ async def trigger_update_python_computed_attributes(
162
149
 
163
150
  for node in nodes:
164
151
  await service.workflow.submit_workflow(
165
- workflow=UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM,
152
+ workflow=COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
166
153
  context=context,
167
154
  parameters={
168
155
  "branch_name": branch_name,
@@ -226,7 +213,7 @@ async def update_computed_attribute_value_jinja2(
226
213
 
227
214
 
228
215
  @flow(
229
- name="process_computed_attribute_jinja2",
216
+ name="computed_attribute_process_jinja2",
230
217
  flow_run_name="Process computed attribute for {computed_attribute_kind}.{computed_attribute_name}",
231
218
  )
232
219
  async def process_jinja2(
@@ -237,20 +224,18 @@ async def process_jinja2(
237
224
  computed_attribute_kind: str,
238
225
  context: InfrahubContext, # noqa: ARG001
239
226
  service: InfrahubServices,
240
- updated_fields: str | None = None,
227
+ updated_fields: list[str] | None = None,
241
228
  ) -> None:
242
229
  log = get_run_logger()
243
230
 
244
231
  await add_tags(branches=[branch_name])
245
- updates: list[str] = []
246
- if isinstance(updated_fields, str):
247
- updates = ujson.loads(updated_fields)
232
+ updates: list[str] = updated_fields or []
248
233
 
249
234
  target_branch_schema = (
250
235
  branch_name if branch_name in registry.get_altered_schema_branches() else registry.default_branch
251
236
  )
252
237
  schema_branch = registry.schema.get_schema_branch(name=target_branch_schema)
253
- await service.client.schema.all(branch=branch_name, refresh=True)
238
+ await service.client.schema.all(branch=branch_name, refresh=True, schema_hash=schema_branch.get_hash())
254
239
 
255
240
  computed_macros = [
256
241
  attrib
@@ -304,11 +289,12 @@ async def trigger_update_jinja2_computed_attributes(
304
289
  ) -> None:
305
290
  await add_tags(branches=[branch_name])
306
291
 
292
+ # NOTE we only need the id of the nodes, we need to ooptimize the query here
307
293
  nodes = await service.client.all(kind=computed_attribute_kind, branch=branch_name)
308
294
 
309
295
  for node in nodes:
310
296
  await service.workflow.submit_workflow(
311
- workflow=PROCESS_COMPUTED_MACRO,
297
+ workflow=COMPUTED_ATTRIBUTE_PROCESS_JINJA2,
312
298
  context=context,
313
299
  parameters={
314
300
  "branch_name": branch_name,
@@ -321,183 +307,39 @@ async def trigger_update_jinja2_computed_attributes(
321
307
  )
322
308
 
323
309
 
324
- @flow(name="computed-attribute-setup", flow_run_name="Setup computed attributes in task-manager")
325
- async def computed_attribute_setup(
326
- service: InfrahubServices, context: InfrahubContext, branch_name: str | None = None
310
+ @flow(name="computed-attribute-setup-jinja2", flow_run_name="Setup computed attributes in task-manager")
311
+ async def computed_attribute_setup_jinja2(
312
+ service: InfrahubServices, context: InfrahubContext, branch_name: str | None = None, event_name: str | None = None
327
313
  ) -> None:
328
- branch_name = branch_name or registry.default_branch
329
-
330
- await add_tags(branches=[branch_name])
331
-
332
314
  log = get_run_logger()
333
- await wait_for_schema_to_converge(branch_name=branch_name, service=service, log=log)
334
315
 
335
- branches_with_diff_from_main = registry.get_altered_schema_branches()
336
- schema_branch = registry.schema.get_schema_branch(name=branch_name)
337
-
338
- async with get_client(sync_client=False) as client:
339
- deployments = {
340
- item.name: item
341
- for item in await client.read_deployments(
342
- deployment_filter=DeploymentFilter(name=DeploymentFilterName(any_=[PROCESS_COMPUTED_MACRO.name]))
316
+ if branch_name:
317
+ await add_tags(branches=[branch_name])
318
+ await wait_for_schema_to_converge(branch_name=branch_name, service=service, log=log)
319
+
320
+ triggers = await gather_trigger_computed_attribute_jinja2()
321
+
322
+ for trigger in triggers:
323
+ if event_name != BranchDeletedEvent.event_name and trigger.branch == branch_name:
324
+ await service.workflow.submit_workflow(
325
+ workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
326
+ context=context,
327
+ parameters={
328
+ "branch_name": trigger.branch,
329
+ "computed_attribute_name": trigger.computed_attribute.attribute.name,
330
+ "computed_attribute_kind": trigger.computed_attribute.kind,
331
+ },
343
332
  )
344
- }
345
- if PROCESS_COMPUTED_MACRO.name not in deployments:
346
- raise ValueError("Unable to find the deployment for PROCESS_COMPUTED_MACRO")
347
333
 
348
- deployment_id_jinja = deployments[PROCESS_COMPUTED_MACRO.name].id
334
+ # Configure all ComputedAttrJinja2Trigger in Prefect
335
+ async with get_client(sync_client=False) as prefect_client:
336
+ await setup_triggers(
337
+ client=prefect_client,
338
+ triggers=triggers,
339
+ trigger_type=TriggerType.COMPUTED_ATTR_JINJA2,
340
+ ) # type: ignore[misc]
349
341
 
350
- automations = await client.read_automations()
351
- existing_computed_attr_automations = ComputedAttributeAutomations.from_prefect(
352
- automations=automations, prefix=PROCESS_JINJA2_AUTOMATION_NAME_PREFIX
353
- )
354
- automations_to_keep = []
355
- mapping = schema_branch.computed_attributes.get_jinja2_target_map()
356
- for computed_attribute, source_node_types in mapping.items():
357
- log.info(f"processing {computed_attribute.key_name}")
358
- scope = registry.default_branch
359
-
360
- match_criteria: dict[str, Any] = {"infrahub.node.kind": source_node_types}
361
- if branches_with_diff_from_main:
362
- match_criteria["infrahub.branch.name"] = [f"!{branch}" for branch in branches_with_diff_from_main]
363
-
364
- automation = AutomationCore(
365
- name=PROCESS_AUTOMATION_NAME.format(
366
- prefix=PROCESS_JINJA2_AUTOMATION_NAME_PREFIX, identifier=computed_attribute.key_name, scope=scope
367
- ),
368
- description=f"Process value of the computed attribute for {computed_attribute.key_name} [{scope}] and branches with the same schema",
369
- enabled=True,
370
- trigger=EventTrigger(
371
- posture=Posture.Reactive,
372
- expect={"infrahub.node.*"},
373
- within=timedelta(0),
374
- match=ResourceSpecification(match_criteria),
375
- threshold=1,
376
- ),
377
- actions=[
378
- RunDeployment(
379
- source="selected",
380
- deployment_id=deployment_id_jinja,
381
- parameters={
382
- "branch_name": "{{ event.resource['infrahub.branch.name'] }}",
383
- "node_kind": "{{ event.resource['infrahub.node.kind'] }}",
384
- "object_id": "{{ event.resource['infrahub.node.id'] }}",
385
- "computed_attribute_name": computed_attribute.attribute.name,
386
- "computed_attribute_kind": computed_attribute.kind,
387
- "updated_fields": "{{ event.payload['fields'] | tojson }}",
388
- "context": {
389
- "__prefect_kind": "json",
390
- "value": {
391
- "__prefect_kind": "jinja",
392
- "template": "{{ event.payload['context'] | tojson }}",
393
- },
394
- },
395
- },
396
- job_variables={},
397
- )
398
- ],
399
- )
400
-
401
- if existing_computed_attr_automations.has(identifier=computed_attribute.key_name, scope=scope):
402
- existing = existing_computed_attr_automations.get(identifier=computed_attribute.key_name, scope=scope)
403
- await client.update_automation(automation_id=existing.id, automation=automation)
404
- automations_to_keep.append(existing.id)
405
- log.info(f"{computed_attribute.key_name} Updated")
406
- else:
407
- automation_id = await client.create_automation(automation=automation)
408
- automations_to_keep.append(automation_id)
409
- log.info(f"{computed_attribute.key_name} Created")
410
-
411
- if branch_name == registry.default_branch:
412
- await service.workflow.submit_workflow(
413
- workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
414
- context=context,
415
- parameters={
416
- "branch_name": registry.default_branch,
417
- "computed_attribute_name": computed_attribute.attribute.name,
418
- "computed_attribute_kind": computed_attribute.kind,
419
- "context": context,
420
- },
421
- )
422
-
423
- for diff_branch in branches_with_diff_from_main:
424
- schema_branch = registry.schema.get_schema_branch(name=diff_branch)
425
-
426
- mapping = schema_branch.computed_attributes.get_jinja2_target_map()
427
- for computed_attribute, source_node_types in mapping.items():
428
- log.info(f"processing {computed_attribute.key_name}")
429
-
430
- automation = AutomationCore(
431
- name=PROCESS_AUTOMATION_NAME.format(
432
- prefix=PROCESS_PYTHON_AUTOMATION_NAME_PREFIX,
433
- identifier=computed_attribute.key_name,
434
- scope=diff_branch,
435
- ),
436
- description=f"Process value of the computed attribute for {computed_attribute.key_name} [{diff_branch}]",
437
- enabled=True,
438
- trigger=EventTrigger(
439
- posture=Posture.Reactive,
440
- expect={"infrahub.node.*"},
441
- within=timedelta(0),
442
- match=ResourceSpecification(
443
- {
444
- "infrahub.node.kind": source_node_types,
445
- "infrahub.branch.name": diff_branch,
446
- }
447
- ),
448
- threshold=1,
449
- ),
450
- actions=[
451
- RunDeployment(
452
- source="selected",
453
- deployment_id=deployment_id_jinja,
454
- parameters={
455
- "branch_name": "{{ event.resource['infrahub.branch.name'] }}",
456
- "node_kind": "{{ event.resource['infrahub.node.kind'] }}",
457
- "object_id": "{{ event.resource['infrahub.node.id'] }}",
458
- "computed_attribute_name": computed_attribute.attribute.name,
459
- "computed_attribute_kind": computed_attribute.kind,
460
- "updated_fields": "{{ event.payload['fields'] | tojson }}",
461
- "context": {
462
- "__prefect_kind": "json",
463
- "value": {
464
- "__prefect_kind": "jinja",
465
- "template": "{{ event.payload['context'] | tojson }}",
466
- },
467
- },
468
- },
469
- job_variables={},
470
- )
471
- ],
472
- )
473
-
474
- if existing_computed_attr_automations.has(identifier=computed_attribute.key_name, scope=diff_branch):
475
- existing = existing_computed_attr_automations.get(
476
- identifier=computed_attribute.key_name, scope=diff_branch
477
- )
478
- await client.update_automation(automation_id=existing.id, automation=automation)
479
- automations_to_keep.append(existing.id)
480
- log.info(f"{computed_attribute.key_name} Updated")
481
- else:
482
- automation_id = await client.create_automation(automation=automation)
483
- automations_to_keep.append(automation_id)
484
- log.info(f"{computed_attribute.key_name} Created")
485
-
486
- if branch_name == diff_branch:
487
- await service.workflow.submit_workflow(
488
- workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
489
- context=context,
490
- parameters={
491
- "branch_name": branch_name,
492
- "computed_attribute_name": computed_attribute.attribute.name,
493
- "computed_attribute_kind": computed_attribute.kind,
494
- "context": context,
495
- },
496
- )
497
-
498
- automations_to_remove = existing_computed_attr_automations.return_obsolete(keep=automations_to_keep)
499
- for automation_to_remove in automations_to_remove:
500
- await client.delete_automation(automation_id=automation_to_remove)
342
+ log.info(f"{len(triggers)} Computed Attribute for Jinja2 automation configuration completed")
501
343
 
502
344
 
503
345
  @flow(
@@ -508,205 +350,48 @@ async def computed_attribute_setup_python(
508
350
  service: InfrahubServices,
509
351
  context: InfrahubContext,
510
352
  branch_name: str | None = None,
353
+ event_name: str | None = None,
511
354
  commit: str | None = None, # noqa: ARG001
512
- trigger_updates: bool = True,
513
355
  ) -> None:
514
356
  log = get_run_logger()
515
357
 
516
358
  branch_name = branch_name or registry.default_branch
517
359
 
518
- await add_tags(branches=[branch_name])
519
-
520
- await wait_for_schema_to_converge(branch_name=branch_name, service=service, log=log)
360
+ if branch_name:
361
+ await add_tags(branches=[branch_name])
362
+ await wait_for_schema_to_converge(branch_name=branch_name, service=service, log=log)
521
363
 
522
- computed_attributes = await _gather_python_transform_attributes(branch_name=branch_name, service=service, log=log)
364
+ triggers_python, triggers_python_query = await gather_trigger_computed_attribute_python(db=service.database)
523
365
 
524
- async with get_client(sync_client=False) as client:
525
- deployments = {
526
- item.name: item
527
- for item in await client.read_deployments(
528
- deployment_filter=DeploymentFilter(
529
- name=DeploymentFilterName(
530
- any_=[UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM.name, QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS.name]
531
- )
532
- )
366
+ for trigger in triggers_python:
367
+ if event_name != BranchDeletedEvent.event_name and trigger.branch == branch_name:
368
+ log.info(
369
+ f"Triggering update for {trigger.computed_attribute.computed_attribute.attribute.name} on {branch_name}"
533
370
  )
534
- }
535
- if UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM.name not in deployments:
536
- raise ValueError("Unable to find the deployment for UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM")
537
- if QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS.name not in deployments:
538
- raise ValueError("Unable to find the deployment for QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS")
539
-
540
- deployment_id_python = deployments[UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM.name].id
541
- deployment_id_query = deployments[QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS.name].id
542
-
543
- automations = await client.read_automations()
544
- existing_computed_attr_process_automations = ComputedAttributeAutomations.from_prefect(
545
- automations=automations, prefix=f"{PROCESS_PYTHON_AUTOMATION_NAME_PREFIX}::{branch_name}::"
546
- )
547
- existing_computed_attr_query_automations = ComputedAttributeAutomations.from_prefect(
548
- automations=automations, prefix=f"{QUERY_AUTOMATION_NAME_PREFIX}::{branch_name}::"
549
- )
550
-
551
- automations_to_keep = []
552
- for computed_attribute in computed_attributes:
553
- log.info(f"processing {computed_attribute.computed_attribute.key_name}")
554
- scope = branch_name
555
-
556
- automation = AutomationCore(
557
- name=PROCESS_AUTOMATION_NAME.format(
558
- prefix=PROCESS_PYTHON_AUTOMATION_NAME_PREFIX,
559
- identifier=computed_attribute.computed_attribute.key_name,
560
- scope=scope,
561
- ),
562
- description=f"Process value of the computed attribute for {computed_attribute.computed_attribute.key_name} [{scope}]",
563
- enabled=True,
564
- trigger=EventTrigger(
565
- posture=Posture.Reactive,
566
- expect={"infrahub.node.*"},
567
- within=timedelta(0),
568
- match=ResourceSpecification(
569
- {
570
- "infrahub.node.kind": [computed_attribute.computed_attribute.kind],
571
- "infrahub.branch.name": branch_name,
572
- }
573
- ),
574
- threshold=1,
575
- ),
576
- actions=[
577
- RunDeployment(
578
- source="selected",
579
- deployment_id=deployment_id_python,
580
- parameters={
581
- "branch_name": "{{ event.resource['infrahub.branch.name'] }}",
582
- "node_kind": "{{ event.resource['infrahub.node.kind'] }}",
583
- "object_id": "{{ event.resource['infrahub.node.id'] }}",
584
- "computed_attribute_name": computed_attribute.computed_attribute.attribute.name,
585
- "computed_attribute_kind": computed_attribute.computed_attribute.kind,
586
- "context": {
587
- "__prefect_kind": "json",
588
- "value": {
589
- "__prefect_kind": "jinja",
590
- "template": "{{ event.payload['context'] | tojson }}",
591
- },
592
- },
593
- },
594
- job_variables={},
595
- )
596
- ],
371
+ await service.workflow.submit_workflow(
372
+ workflow=TRIGGER_UPDATE_PYTHON_COMPUTED_ATTRIBUTES,
373
+ context=context,
374
+ parameters={
375
+ "branch_name": branch_name,
376
+ "computed_attribute_name": trigger.computed_attribute.computed_attribute.attribute.name,
377
+ "computed_attribute_kind": trigger.computed_attribute.computed_attribute.kind,
378
+ },
597
379
  )
598
380
 
599
- if existing_computed_attr_process_automations.has(
600
- identifier=computed_attribute.computed_attribute.key_name, scope=scope
601
- ):
602
- existing = existing_computed_attr_process_automations.get(
603
- identifier=computed_attribute.computed_attribute.key_name, scope=scope
604
- )
605
- await client.update_automation(automation_id=existing.id, automation=automation)
606
- log.info(f"Process {computed_attribute.computed_attribute.key_name} Updated")
607
- automations_to_keep.append(existing.id)
608
- else:
609
- automation_id = await client.create_automation(automation=automation)
610
- automations_to_keep.append(automation_id)
611
- log.info(f"Process {computed_attribute.computed_attribute.key_name} Created")
612
-
613
- automation = AutomationCore(
614
- name=QUERY_AUTOMATION_NAME.format(
615
- prefix=QUERY_AUTOMATION_NAME_PREFIX,
616
- identifier=computed_attribute.computed_attribute.key_name,
617
- scope=scope,
618
- ),
619
- description=f"Query the computed attribute targets for {computed_attribute.computed_attribute.key_name} [{scope}]",
620
- enabled=True,
621
- trigger=EventTrigger(
622
- posture=Posture.Reactive,
623
- expect={"infrahub.node.*"},
624
- within=timedelta(0),
625
- match=ResourceSpecification(
626
- {
627
- "infrahub.node.kind": computed_attribute.query_models,
628
- "infrahub.branch.name": branch_name,
629
- }
630
- ),
631
- threshold=1,
632
- ),
633
- actions=[
634
- RunDeployment(
635
- source="selected",
636
- deployment_id=deployment_id_query,
637
- parameters={
638
- "branch_name": "{{ event.resource['infrahub.branch.name'] }}",
639
- "node_kind": "{{ event.resource['infrahub.node.kind'] }}",
640
- "object_id": "{{ event.resource['infrahub.node.id'] }}",
641
- "context": {
642
- "__prefect_kind": "json",
643
- "value": {
644
- "__prefect_kind": "jinja",
645
- "template": "{{ event.payload['context'] | tojson }}",
646
- },
647
- },
648
- },
649
- job_variables={},
650
- )
651
- ],
652
- )
381
+ async with get_client(sync_client=False) as prefect_client:
382
+ await setup_triggers(
383
+ client=prefect_client,
384
+ triggers=triggers_python,
385
+ trigger_type=TriggerType.COMPUTED_ATTR_PYTHON,
386
+ ) # type: ignore[misc]
387
+ log.info(f"{len(triggers_python)} Computed Attribute for Python automation configuration completed")
653
388
 
654
- if existing_computed_attr_query_automations.has(
655
- identifier=computed_attribute.computed_attribute.key_name, scope=scope
656
- ):
657
- existing = existing_computed_attr_query_automations.get(
658
- identifier=computed_attribute.computed_attribute.key_name, scope=scope
659
- )
660
- await client.update_automation(automation_id=existing.id, automation=automation)
661
- automations_to_keep.append(existing.id)
662
- log.info(f"Query {computed_attribute.computed_attribute.key_name} Updated")
663
- else:
664
- automation_id = await client.create_automation(automation=automation)
665
- automations_to_keep.append(automation_id)
666
- log.info(f"Query {computed_attribute.computed_attribute.key_name} Created")
667
-
668
- if trigger_updates:
669
- await service.workflow.submit_workflow(
670
- workflow=TRIGGER_UPDATE_PYTHON_COMPUTED_ATTRIBUTES,
671
- context=context,
672
- parameters={
673
- "branch_name": branch_name,
674
- "computed_attribute_name": computed_attribute.computed_attribute.attribute.name,
675
- "computed_attribute_kind": computed_attribute.computed_attribute.kind,
676
- "context": context,
677
- },
678
- )
679
-
680
- automations_to_remove = existing_computed_attr_process_automations.return_obsolete(keep=automations_to_keep)
681
- for automation_to_remove in automations_to_remove:
682
- await client.delete_automation(automation_id=automation_to_remove)
683
-
684
- automations_to_remove = existing_computed_attr_query_automations.return_obsolete(keep=automations_to_keep)
685
- for automation_to_remove in automations_to_remove:
686
- await client.delete_automation(automation_id=automation_to_remove)
687
-
688
-
689
- @flow(
690
- name="computed-attribute-remove-python",
691
- flow_run_name="Remove Python based computed attributes on branch={branch_name}",
692
- )
693
- async def computed_attribute_remove_python(
694
- branch_name: str,
695
- ) -> None:
696
- async with get_client(sync_client=False) as client:
697
- automations = await client.read_automations()
698
- existing_computed_attr_process_automations = ComputedAttributeAutomations.from_prefect(
699
- automations=automations, prefix=f"{PROCESS_PYTHON_AUTOMATION_NAME_PREFIX}::{branch_name}::"
700
- )
701
- existing_computed_attr_query_automations = ComputedAttributeAutomations.from_prefect(
702
- automations=automations, prefix=f"{QUERY_AUTOMATION_NAME_PREFIX}::{branch_name}::"
703
- )
704
-
705
- for automation_id in existing_computed_attr_process_automations.all_automation_ids:
706
- await client.delete_automation(automation_id=automation_id)
707
-
708
- for automation_id in existing_computed_attr_query_automations.all_automation_ids:
709
- await client.delete_automation(automation_id=automation_id)
389
+ await setup_triggers(
390
+ client=prefect_client,
391
+ triggers=triggers_python_query,
392
+ trigger_type=TriggerType.COMPUTED_ATTR_PYTHON_QUERY,
393
+ ) # type: ignore[misc]
394
+ log.info(f"{len(triggers_python_query)} Computed Attribute for Python Query automation configuration completed")
710
395
 
711
396
 
712
397
  @flow(
@@ -739,7 +424,7 @@ async def query_transform_targets(
739
424
  if subscriber.kind in nodes_with_computed_attributes:
740
425
  for computed_attribute in nodes_with_computed_attributes[subscriber.kind]:
741
426
  await service.workflow.submit_workflow(
742
- workflow=UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM,
427
+ workflow=COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
743
428
  context=context,
744
429
  parameters={
745
430
  "branch_name": branch_name,
@@ -751,55 +436,6 @@ async def query_transform_targets(
751
436
  )
752
437
 
753
438
 
754
- async def _gather_python_transform_attributes(
755
- branch_name: str, service: InfrahubServices, log: logging.Logger | logging.LoggerAdapter
756
- ) -> list[PythonTransformComputedAttribute]:
757
- schema_branch = registry.schema.get_schema_branch(name=branch_name)
758
- branches_with_diff_from_main = registry.get_altered_schema_branches()
759
-
760
- transform_attributes = schema_branch.computed_attributes.python_attributes_by_transform
761
-
762
- transform_names = list(transform_attributes.keys())
763
- if not transform_names:
764
- return []
765
-
766
- transforms = await service.client.filters(
767
- kind="CoreTransformPython",
768
- branch=branch_name,
769
- prefetch_relationships=True,
770
- populate_store=True,
771
- name__values=transform_names,
772
- )
773
-
774
- found_transforms_names = [transform.name.value for transform in transforms]
775
- for transform_name in transform_names:
776
- if transform_name not in found_transforms_names:
777
- log.warning(
778
- msg=f"The transform {transform_name} is assigned to a computed attribute but the transform could not be found in the database."
779
- )
780
-
781
- repositories = await service.client.get_list_repositories()
782
- computed_attributes: list[PythonTransformComputedAttribute] = []
783
- for transform in transforms:
784
- for attribute in transform_attributes[transform.name.value]:
785
- python_transform_computed_attribute = PythonTransformComputedAttribute(
786
- name=transform.name.value,
787
- repository_id=transform.repository.peer.id,
788
- repository_name=transform.repository.peer.name.value,
789
- repository_kind=transform.repository.peer.typename,
790
- query_name=transform.query.peer.name.value,
791
- query_models=transform.query.peer.models.value,
792
- computed_attribute=attribute,
793
- default_schema=branch_name not in branches_with_diff_from_main,
794
- )
795
- python_transform_computed_attribute.populate_branch_commit(
796
- repository_data=repositories.get(transform.repository.peer.name.value)
797
- )
798
- computed_attributes.append(python_transform_computed_attribute)
799
-
800
- return computed_attributes
801
-
802
-
803
439
  GATHER_GRAPHQL_QUERY_SUBSCRIBERS = """
804
440
  query GatherGraphQLQuerySubscribers($members: [ID!]) {
805
441
  CoreGraphQLQueryGroup(members__ids: $members) {