mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(autogpt_server): Incorrect graph reassignment
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user