Skip to content

Commit

Permalink
fix(autogpt_server): Incorrect graph reassignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftyos committed Aug 5, 2024
1 parent 4cf1dd3 commit 9ae6389
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions rnd/autogpt_server/autogpt_server/data/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ def subgraph_map(self) -> dict[str, str]:
)
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.
"""
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]
Expand Down
3 changes: 2 additions & 1 deletion rnd/autogpt_server/autogpt_server/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ async def create_graph(
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
)
Expand All @@ -467,7 +468,7 @@ async def create_graph(

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)

Expand Down

0 comments on commit 9ae6389

Please sign in to comment.