Skip to content

Commit d44667b

Browse files
authored
[core][feat] Allow update node with force (#2047)
1 parent dc7d2fa commit d44667b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

fixcore/fixcore/db/graphdb.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ async def update_deferred_edges(self, edges: List[Tuple[NodeId, NodeId, str]], t
100100

101101
@abstractmethod
102102
async def update_node(
103-
self, model: Model, node_id: NodeId, patch_or_replace: Json, replace: bool, section: Optional[str]
103+
self,
104+
model: Model,
105+
node_id: NodeId,
106+
patch_or_replace: Json,
107+
replace: bool,
108+
section: Optional[str],
109+
force: bool = False,
104110
) -> Json:
105111
pass
106112

@@ -335,9 +341,15 @@ def deletion_query(edge_collection: str) -> str:
335341
return updated_edges, deleted_edges
336342

337343
async def update_node(
338-
self, model: Model, node_id: NodeId, patch_or_replace: Json, replace: bool, section: Optional[str]
344+
self,
345+
model: Model,
346+
node_id: NodeId,
347+
patch_or_replace: Json,
348+
replace: bool,
349+
section: Optional[str],
350+
force: bool = False,
339351
) -> Json:
340-
return await self.update_node_with(self.db, model, node_id, patch_or_replace, replace, section)
352+
return await self.update_node_with(self.db, model, node_id, patch_or_replace, replace, section, force)
341353

342354
async def update_node_with(
343355
self,
@@ -347,6 +359,7 @@ async def update_node_with(
347359
patch_or_replace: Json,
348360
replace: bool,
349361
section: Optional[str],
362+
force: bool = False,
350363
) -> Json:
351364
log.info(f"Update node with node_id={node_id}, section={section}, replace={replace}, update={patch_or_replace}")
352365
node = await self.by_id_with(db, node_id)
@@ -400,7 +413,7 @@ async def update_resolved_property(id_prop: ResolveProp, patch: Json, history: b
400413
for prop in ra.resolved_props():
401414
if value_in_path(node, prop.extract_path) != (nv := value_in_path(update, prop.extract_path)):
402415
set_value_in_path(nv, prop.to_path, changes)
403-
if changes:
416+
if changes or force:
404417
await update_resolved_property(rid, changes, False)
405418
await update_resolved_property(rid, changes, True)
406419

@@ -1649,7 +1662,13 @@ async def update_deferred_edges(self, edges: List[Tuple[NodeId, NodeId, str]], t
16491662
return updated, deleted
16501663

16511664
async def update_node(
1652-
self, model: Model, node_id: NodeId, patch_or_replace: Json, replace: bool, section: Optional[str]
1665+
self,
1666+
model: Model,
1667+
node_id: NodeId,
1668+
patch_or_replace: Json,
1669+
replace: bool,
1670+
section: Optional[str],
1671+
force: bool = False,
16531672
) -> Json:
16541673
result = await self.real.update_node(model, node_id, patch_or_replace, replace, section)
16551674
await self.event_sender.core_event(CoreEvent.NodeUpdated, {"graph": self.graph_name, "section": section})

fixcore/fixcore/web/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ async def update_node(self, request: Request, deps: TenantDependencies) -> Strea
10141014
section = section_of(request)
10151015
graph = deps.db_access.get_graph_db(graph_id)
10161016
patch = await self.json_from_request(request)
1017+
force = request.query.get("force", "false").lower() == "true"
10171018
md = await deps.model_handler.load_model(graph_id)
10181019
node: Optional[Json] = None
10191020
if section == Section.metadata:
@@ -1023,7 +1024,7 @@ async def update_node(self, request: Request, deps: TenantDependencies) -> Strea
10231024
async for n in graph.update_nodes_desired(md, patch, [node_id]):
10241025
node = n
10251026
else:
1026-
node = await graph.update_node(md, node_id, patch, False, section)
1027+
node = await graph.update_node(md, node_id, patch, False, section, force)
10271028
if node is None:
10281029
return web.HTTPNotFound(text=f"No such node with id {node_id} in graph {graph_id}")
10291030
return await single_result(request, node)

0 commit comments

Comments
 (0)