Skip to content

Commit

Permalink
fix: handle error with returning user object from database_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ntindle committed Oct 18, 2024
1 parent 9c07633 commit b624510
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,8 @@ def _set_user_integration_creds(
self.db_manager.update_user_metadata(user_id, raw_metadata)

def _get_user_metadata(self, user_id: str) -> UserMetadataRaw:
user = self.db_manager.get_user(user_id=user_id)
return (
UserMetadataRaw.model_validate(user.metadata)
if user.metadata
else UserMetadataRaw()
)
metadata: UserMetadataRaw = self.db_manager.get_user_metadata(user_id=user_id)
return metadata

def locked_user_metadata(self, user_id: str):
key = (self.db_manager, f"user:{user_id}", "metadata")
Expand Down
4 changes: 2 additions & 2 deletions autogpt_platform/backend/backend/data/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ async def get_incomplete_executions(
return [ExecutionResult.from_db(execution) for execution in executions]


async def get_user(user_id: str) -> User:
async def get_user_metadata(user_id: str) -> UserMetadataRaw:
user = await User.prisma().find_unique_or_raise(
where={"id": user_id},
)
return user
return UserMetadataRaw.model_validate(user.metadata) if user.metadata else UserMetadataRaw()


async def update_user_metadata(user_id: str, metadata: UserMetadataRaw):
Expand Down
4 changes: 2 additions & 2 deletions autogpt_platform/backend/backend/executor/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
get_execution_results,
get_incomplete_executions,
get_latest_execution,
get_user,
get_user_metadata,
update_execution_status,
update_graph_execution_stats,
update_node_execution_stats,
Expand Down Expand Up @@ -77,5 +77,5 @@ def wrapper(self, *args: P.args, **kwargs: P.kwargs) -> R:
)

# User + User Metadata
get_user = exposed_run_and_wait(get_user)
get_user_metadata = exposed_run_and_wait(get_user_metadata)
update_user_metadata = exposed_run_and_wait(update_user_metadata)

0 comments on commit b624510

Please sign in to comment.