Skip to content

Commit 31d7940

Browse files
committed
fix: make sure to lock on resource manager allocations
We should also lock regardless of the branch when allocating from a resource manager. Signed-off-by: Fatih Acar <[email protected]>
1 parent b43124e commit 31d7940

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

backend/infrahub/lock_getter.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import hashlib
2+
from typing import TYPE_CHECKING
23

34
from infrahub.core.branch import Branch
45
from infrahub.core.constants import InfrahubKind
@@ -7,6 +8,9 @@
78
from infrahub.core.schema.schema_branch import SchemaBranch
89
from infrahub.lock import build_object_lock_name
910

11+
if TYPE_CHECKING:
12+
from infrahub.core.relationship import RelationshipManager
13+
1014
KINDS_CONCURRENT_MUTATIONS_NOT_ALLOWED = [InfrahubKind.GENERICGROUP]
1115

1216

@@ -75,11 +79,20 @@ def get_lock_names_on_object_mutation(node: Node, branch: Branch, schema_branch:
7579
Lock names include kind, some generic kinds, and values of attributes of corresponding uniqueness constraints.
7680
"""
7781

82+
lock_names = []
83+
# Check if node is using resource manager allocation
84+
for rel_name in node._relationships:
85+
rel_manager: RelationshipManager = getattr(node, rel_name)
86+
for rel in rel_manager._relationships:
87+
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()
91+
7892
if not branch.is_default and not _should_kind_be_locked_on_any_branch(node.get_kind(), schema_branch):
79-
return []
93+
return lock_names
8094

8195
lock_kinds = _get_kinds_to_lock_on_object_mutation(node.get_kind(), schema_branch)
82-
lock_names = []
8396
for kind in lock_kinds:
8497
schema = schema_branch.get(name=kind)
8598
ucs = schema.uniqueness_constraints

0 commit comments

Comments
 (0)