mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-16 09:46:07 -05:00
fix(library): validate folder existence when updating agent folder ID
- Enhanced the `update_library_agent` function to verify that the specified folder ID belongs to the user and is not deleted before updating the agent's folder ID. - This change improves error handling by raising a `NotFoundError` if the folder is not found, ensuring better data integrity and user feedback during agent updates.
This commit is contained in:
@@ -690,7 +690,20 @@ async def update_library_agent(
|
||||
update_fields["settings"] = SafeJson(settings.model_dump())
|
||||
if folder_id is not None:
|
||||
# Empty string means "move to root" (no folder)
|
||||
update_fields["folderId"] = None if folder_id == "" else folder_id
|
||||
if folder_id == "":
|
||||
update_fields["folderId"] = None
|
||||
else:
|
||||
# Verify folder belongs to user
|
||||
folder = await prisma.models.LibraryFolder.prisma().find_first(
|
||||
where={
|
||||
"id": folder_id,
|
||||
"userId": user_id,
|
||||
"isDeleted": False,
|
||||
}
|
||||
)
|
||||
if not folder:
|
||||
raise NotFoundError(f"Folder #{folder_id} not found")
|
||||
update_fields["folderId"] = folder_id
|
||||
|
||||
try:
|
||||
# If graph_version is provided, update to that specific version
|
||||
|
||||
Reference in New Issue
Block a user