Skip to content

Commit 9eefa2f

Browse files
committed
post review fixes
Signed-off-by: Fatih Acar <[email protected]>
1 parent 3aa9ba8 commit 9eefa2f

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

backend/infrahub/graphql/mutations/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ async def _call_mutate_update(
224224
kind=obj.get_kind(),
225225
id=obj.get_id(),
226226
branch=branch,
227-
include_owner=True,
228-
include_source=True,
229227
)
230228
await preview_obj.from_graphql(db=db, data=data, process_pools=False)
231229

backend/infrahub/lock_getter.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _get_kinds_to_lock_on_object_mutation(kind: str, schema_branch: SchemaBranch
1818
it means node schema overrided this constraint, in which case we only need to lock on the generic.
1919
"""
2020

21-
node_schema = schema_branch.get(name=kind)
21+
node_schema = schema_branch.get(name=kind, duplicate=False)
2222

2323
schema_uc = None
2424
kinds = []
@@ -33,7 +33,7 @@ def _get_kinds_to_lock_on_object_mutation(kind: str, schema_branch: SchemaBranch
3333

3434
node_schema_kind_removed = False
3535
for generic_kind in generics_kinds:
36-
generic_uc = schema_branch.get(name=generic_kind).uniqueness_constraints
36+
generic_uc = schema_branch.get(name=generic_kind, duplicate=False).uniqueness_constraints
3737
if generic_uc:
3838
kinds.append(generic_kind)
3939
if not node_schema_kind_removed and generic_uc == schema_uc:
@@ -52,34 +52,28 @@ def _hash(value: str) -> str:
5252

5353
def get_lock_names_on_object_mutation(node: Node, schema_branch: SchemaBranch) -> list[str]:
5454
"""
55-
Return lock names for object on which we want to avoid concurrent mutation (create/update). Except for some specific kinds,
56-
concurrent mutations are only allowed on non-main branch as objects validations will be performed at least when merging in main branch.
57-
Lock names include kind, some generic kinds, and values of attributes of corresponding uniqueness constraints.
55+
Return lock names for object on which we want to avoid concurrent mutation (create/update).
56+
Lock names include kind, some generic kinds, resource pool ids, and values of attributes of corresponding uniqueness constraints.
5857
"""
5958

60-
lock_names: list[str] = []
61-
62-
def _add_pool_lock(pool_id: str) -> None:
63-
lock_name = f"resource_pool.{pool_id}"
64-
if lock_name not in lock_names:
65-
lock_names.append(lock_name)
59+
lock_names: set[str] = set()
6660

6761
# Check if node is using resource manager allocation via attributes
68-
for attr_name in getattr(node, "_attributes", []):
62+
for attr_name in node.get_schema().attribute_names:
6963
attribute = getattr(node, attr_name, None)
7064
if attribute is not None and getattr(attribute, "from_pool", None) and "id" in attribute.from_pool:
71-
_add_pool_lock(attribute.from_pool["id"])
65+
lock_names.add(f"resource_pool.{attribute.from_pool['id']}")
7266

7367
# Check if relationships allocate resources
7468
for rel_name in node._relationships:
7569
rel_manager: RelationshipManager = getattr(node, rel_name)
7670
for rel in rel_manager._relationships:
7771
if rel.from_pool and "id" in rel.from_pool:
78-
_add_pool_lock(rel.from_pool["id"])
72+
lock_names.add(f"resource_pool.{rel.from_pool['id']}")
7973

8074
lock_kinds = _get_kinds_to_lock_on_object_mutation(node.get_kind(), schema_branch)
8175
for kind in lock_kinds:
82-
schema = schema_branch.get(name=kind)
76+
schema = schema_branch.get(name=kind, duplicate=False)
8377
ucs = schema.uniqueness_constraints
8478
if ucs is None:
8579
continue
@@ -119,6 +113,6 @@ def _add_pool_lock(pool_id: str) -> None:
119113
continue
120114

121115
partial_lock_name = kind + "." + ".".join(ucs_lock_names)
122-
lock_names.append(build_object_lock_name(partial_lock_name))
116+
lock_names.add(build_object_lock_name(partial_lock_name))
123117

124-
return lock_names
118+
return list(lock_names)

0 commit comments

Comments
 (0)