Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): fix get agent db function #9350

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions autogpt_platform/backend/backend/server/v2/store/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from datetime import datetime
from typing import Optional

import fastapi
import prisma.enums
import prisma.errors
import prisma.models
Expand Down Expand Up @@ -794,7 +793,7 @@ async def get_my_agents(

async def get_agent(
store_listing_version_id: str, version_id: Optional[int]
) -> GraphModel:
) -> Optional[GraphModel]:
"""Get agent using the version ID and store listing version ID."""
try:
store_listing_version = (
Expand All @@ -804,10 +803,8 @@ async def get_agent(
)

if not store_listing_version or not store_listing_version.Agent:
raise fastapi.HTTPException(
status_code=404,
detail=f"Store listing version {store_listing_version_id} not found",
)
logger.error(f"Store listing version {store_listing_version_id} not found")
return None

agent = store_listing_version.Agent

Expand All @@ -816,14 +813,12 @@ async def get_agent(
)

if not graph:
raise fastapi.HTTPException(
status_code=404, detail=f"Agent {agent.id} not found"
)
logger.error(f"Agent {agent.id} not found")
return None

graph.version = 1
graph.is_template = False
graph.is_active = True
delattr(graph, "user_id")

return graph

Expand Down
7 changes: 7 additions & 0 deletions autogpt_platform/backend/backend/server/v2/store/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@ async def download_agent_file(
store_listing_version_id=store_listing_version_id, version_id=version
)

if not graph_data:
raise fastapi.HTTPException(
status_code=404, detail=f"Graph with {store_listing_version_id} no found"
)

graph_data.clean_graph()
graph_date_dict = jsonable_encoder(graph_data)

Expand All @@ -620,6 +625,8 @@ def remove_credentials(obj):
del obj["credentials"]
if "creds" in obj:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a greater utility function that gets called :)

we can probably also strip anything that has secret = true

del obj["creds"]
if "user_id" in obj:
del obj["user_id"]

for value in obj.values():
remove_credentials(value)
Expand Down
Loading