Skip to content

Commit bde76ed

Browse files
committed
fix(backend): lock on resource manager attributes
Signed-off-by: Fatih Acar <[email protected]>
1 parent bc2c346 commit bde76ed

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

backend/infrahub/lock_getter.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,25 @@ def get_lock_names_on_object_mutation(node: Node, branch: Branch, schema_branch:
7979
Lock names include kind, some generic kinds, and values of attributes of corresponding uniqueness constraints.
8080
"""
8181

82-
lock_names = []
83-
# Check if node is using resource manager allocation
82+
lock_names: list[str] = []
83+
84+
def _add_pool_lock(pool_id: str) -> None:
85+
lock_name = f"resource_pool.{pool_id}"
86+
if lock_name not in lock_names:
87+
lock_names.append(lock_name)
88+
89+
# Check if node is using resource manager allocation via attributes
90+
for attr_name in getattr(node, "_attributes", []):
91+
attribute = getattr(node, attr_name, None)
92+
if attribute is not None and getattr(attribute, "from_pool", None) and "id" in attribute.from_pool:
93+
_add_pool_lock(attribute.from_pool["id"])
94+
95+
# Check if relationships allocate resources
8496
for rel_name in node._relationships:
8597
rel_manager: RelationshipManager = getattr(node, rel_name)
8698
for rel in rel_manager._relationships:
8799
if rel.from_pool and "id" in rel.from_pool:
88-
lock_names.append(
89-
f"resource_pool.{rel.from_pool['id']}"
90-
) # lock on resource manager using the same lock we have in get_resource()
100+
_add_pool_lock(rel.from_pool["id"])
91101

92102
if not branch.is_default and not _should_kind_be_locked_on_any_branch(node.get_kind(), schema_branch):
93103
return lock_names
@@ -99,7 +109,7 @@ def get_lock_names_on_object_mutation(node: Node, branch: Branch, schema_branch:
99109
if ucs is None:
100110
continue
101111

102-
ucs_lock_names = []
112+
ucs_lock_names: list[str] = []
103113
uc_attributes_names = set()
104114

105115
for uc in ucs:

0 commit comments

Comments
 (0)