fix(autogpt_server): Incorrect graph reassignment

This commit is contained in:
SwiftyOS
2024-08-05 16:16:56 +02:00
parent 4cf1dd30f1
commit 9ae6389c6c
2 changed files with 5 additions and 4 deletions

View File

@@ -123,7 +123,7 @@ class Graph(GraphMeta):
)
return subgraph_map
def reassign_ids(self):
def reassign_ids(self, reassign_graph_id: bool = False):
"""
Reassigns all IDs in the graph to new UUIDs.
This method can be used before storing a new graph to the database.
@@ -131,12 +131,12 @@ class Graph(GraphMeta):
self.validate_graph()
id_map = {
self.id: str(uuid.uuid4()),
**{node.id: str(uuid.uuid4()) for node in self.nodes},
**{subgraph_id: str(uuid.uuid4()) for subgraph_id in self.subgraphs},
}
self.id = id_map[self.id]
if reassign_graph_id:
self.id = str(uuid.uuid4())
for node in self.nodes:
node.id = id_map[node.id]

View File

@@ -452,6 +452,7 @@ class AgentServer(AppService):
if create_graph.graph:
graph = create_graph.graph
elif create_graph.template_id:
# Create a new graph from a template
graph = await graph_db.get_graph(
create_graph.template_id, create_graph.template_version, template=True
)
@@ -467,7 +468,7 @@ class AgentServer(AppService):
graph.is_template = is_template
graph.is_active = not is_template
graph.reassign_ids()
graph.reassign_ids(reassign_graph_id=True)
return await graph_db.create_graph(graph)